Part Number Hot Search : 
SMLJ170 AN6657S BZW04P53 HMD1M4Z1 100R2 3BR1765 LTC421 2C256
Product Description
Full Text Search
 

To Download 89LP4052 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  features ? compatible with mcs ? 51 products  20 mips throughput at 20 mhz clock freque ncy and 2.4v, 85c operating conditions  single clock cycle per byte fetch  2/4k bytes of in-system programmable (isp) flash memory ? serial interface for program downloading ? 32-byte fast page programming mode ? 32-byte user signature array  2.4v to 5.5v v cc operating range  fully static operation: 0 hz to 20 mhz  2-level program memory lock  256 x 8 internal ram  hardware multiplier  15 programmable i/o lines  configurable i/o with quasi-bidirectional, input, push-pull output, and open-drain modes  enhanced uart with automatic address r ecognition and framing error detection  enhanced spi with double-buffered send/receive  programmable watchdog timer with software reset  4-level interrupt priority  analog comparator with select able interrupt and debouncing  two 16-bit enhanced timer/counters with 8-bit pwm  brown-out detector and power-off flag  internal power-on reset  low power idle and power-down modes  interrupt recovery from power-down mode 1. description the at89lp2052/lp4052 is a low-power, high-performance cmos 8-bit microcon- troller with 2/4k bytes of in-system programmable flash memory. the device is manufactured using atmel's high-density nonvolatile memory technology and is com- patible with the industry-standard mcs-51 instruction set. the at89lp2052/lp4052 is built around an enhanced cpu core that can fetch a single byte from memory every clock cycle. in the classic 8051 architecture , each fetch required 6 clock cycles, forc- ing instructions to execute in 12, 24 or 48 clock cycles. in the at89lp2052/lp4052 cpu, instructions need only 1 to 4 clock cycl es providing 6 to 12 times more through- put than the standard 8051. seventy percent of instructions need only as many clock cycles as they have bytes to execute, and most of the remaining instructions require only one additional clock. the enhanced cpu core is capable of 20 mips throughput whereas the classic 8051 cpu can deliver only 4 mips at the same current consump- tion. conversely, at the same throughput as the classic 8051, the new cpu core runs at a much lower speed and thereby greatly reduces power consumption. 8-bit microcontroller with 2/4-kbyte flash at89lp2052 at89LP4052 3547f?micro?6/06
2 3547f?micro?6/06 at89lp2052/lp4052 the two timer/counters in the at89lp2052/lp4052 are enhanced with two new modes. mode 0 can be configured as a variable 9- to 16-bit timer/counter and mode 1 can be configured as a 16-bit auto-reload timer/counter. in addition both timer/counters may be configured as 8-bit pulse width modulators with 8-bit prescalers. the i/o ports of the at89lp2052/lp4052 can be independently configured in one of four oper- ating modes. in quasi-bidirectional mode, the ports operate as in the classic 8051. in input mode, the ports are tri-stated. push-pull output mode provides full cmos drivers and open-drain mode provides just a pull-down. 2. pin configuration 2.1 20-lead pdip/soic/tssop 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 (vpp) rst (rxd) p3.0 (txd) p3.1 xtal2 xtal1 (int0) p3.2 (int1) p3.3 (t0) p3.4 (t1) p3.5 gnd vcc p1.7 (sck) p1.6 (miso) p1.5 (mosi) p1.4 (ss) p1.3 p1.2 p1.1 (ain1) p1.0 (ain0) p3.7 (sysclk)
3 3547f?micro?6/06 at89lp2052/lp4052 3. pin description pin symbol type description 1rst i i rst : external active-high reset input. vpp : parallel programming voltage. raise to 12v to enable programming. 2p3.0 i/o i p3.0 : user-configurable i/o port 3 bit 0. rxd : serial port receiver input. 3p3.1 i/o o p3.1 : user-configurable i/o port 3 bit 1. txd : serial port transmitter output. 4xtal2o xtal2 : output from inverting oscillator amplifier. 5xtal1 i xtal1 : input to the inverting oscillator amplif ier and internal clock generation circuits. 6p3.2 i/o i p3.2 : user-configurable i/o port 3 bit 2. int0 : external interrupt 0 input. 7p3.3 i/o i p3.3 : user-configurable i/o port 3 bit 3. int1 : external interrupt 1input. 8p3.4 i/o i/o p3.4 : user-configurable i/o port 3 bit 4. t0 : timer 0 counter input or pwm output 9p3.5 i/o i/o p3.5 : user-configurable i/o port 3 bit 5. t1 : timer 1 counter input or pwm output 10 gnd i ground 11 p3.7 i/o o p3.7 : user-configurable i/o port 3 bit 7. sysclk : system clock output when system clock fuse is enabled. 12 p1.0 i/o i p1.0 : user-configurable i/o port 1 bit 0. ain0 : analog comparator positive input. 13 p1.1 i/o i p1.1 : user-configurable i/o port 1 bit 1. ain1 : analog comparator negative input. 14 p1.2 i/o p1.2 : user-configurable i/o port 1 bit 2. 15 p1.3 i/o p1.3 : user-configurable i/o port 1 bit 3 16 p1.4 i/o i p1.4 : user-configurable i/o port 1 bit 4. ss : spi slave select. 17 p1.5 i/o i/o p1.5 : user-configurable i/o port 1 bit 5. mosi : spi master-out/slave-in. when configured as mast er, this pin is an output. when configured as slave, this pin is an input. 18 p1.6 i/o i/o p1.6 : user-configurable i/o port 1 bit 6. miso : spi master-in/slave-out. when configured as mast er, this pin is an input. when configured as slave, this pin is an output. 19 p1.7 i/o i/o p1.7 : user-configurable i/o port 1 bit 7. sck : spi clock. when configured as master, this pin is an output. when configured as slave, this pin is an input. 20 vcc i supply voltage
4 3547f?micro?6/06 at89lp2052/lp4052 4. block diagram 5. memory organization the at89lp2052/lp4052 uses a harvard architecture with separate address spaces for pro- gram and data memory. the program memory has a regular linear address space with support for up to 64k bytes of directly addressable application code. the data memory has 256 bytes of internal ram which is divided in to regions that may be accessed by different instruction classes. the at89lp2052/lp4052 does not support external ram. 5.1 program memory the at89lp2052/lp4052 contains 2/4k bytes of on-chip in-system programmable flash mem- ory for program storage. the flash memory has an endurance of at least 10,000 write/erase cycles. section 22. ?programming the flash memory? on page 54 contains a detailed description on flash programming in isp or parallel programming mode. the reset and interrupt vectors are located within the first 59 bytes of program memory (see section 13. ?interrupts? on page 13 ). constant tables can be allocated within the entire 2/4-kbyte program memory address space for access by the movc instruction. single cycle 8051 cpu 2/4-kbyte flash 256-byte ram port 3 configurable i/o port 1 configurable i/o uart spi timer 0 timer 1 analog comparator watchdog timer configurable oscillator cpu clock crystal or resonator
5 3547f?micro?6/06 at89lp2052/lp4052 figure 5-1. program memory map 5.2 data memory the at89lp2052/lp4052 contains 256 bytes of general sram data memory plus 128 bytes of i/o memory. the lower 128 bytes of data memory may be accessed through both direct and indirect addressing. the upper 128 bytes of data memory and the 128 bytes of i/o memory share the same address space (see figure 5-2 ). the upper 128 bytes of data memory may only be accessed using indirect addressing. the i/o memory can only be accessed through direct addressing and contains the special function registers (sfrs). the lowest 32 bytes of data memory are grouped into 4 banks of 8 register s each. the rs0 and rs1 bits (psw.3 and psw.4) select which register bank is in use. instructions using register addressing will only access the currently specified bank. the at89lp2052/lp4052 does not support external data memory. figure 5-2. data memory map program memory at89lp2052 0000 07ff 0000 0fff program memory at89LP4052 ffh upper 128 80h 7fh lower 128 0 accessible by indirect addressing only ffh 80h special function registers ports status and control bits registers stack pointer accumulator (etc.) timers accessible by direct and indirect addressing accessible by direct addressing
6 3547f?micro?6/06 at89lp2052/lp4052 6. special function registers a map of the on-chip memory area called the special function register (sfr) space is shown in table 6-1 . note that not all of the addresses are occupied, and unoccupied addresses may not be imple- mented on the chip. read accesse s to these addresses will in gen eral return ra ndom data, and write accesses will have an indeterminate effect . user software should no t write to these unlisted locations, since they may be used in future products to invoke new features. note: *these sfrs are bit-addressable. table 6-1. at89lp2052/lp4052 sfr map and reset values 0f8h 0ffh 0f0h b* 0000 0000 0f7h 0e8h 0efh 0e0h acc* 0000 0000 0e7h 0d8h 0dfh 0d0h psw* 0000 0000 spcr 0000 0000 0d7h 0c8h 0cfh 0c0h p1m0 1111 1111 p1m1 0000 0000 p3m0 1111 1111 p3m1 0000 0000 0c7h 0b8h ip* x0x0 0000 saden 0000 0000 0bfh 0b0h p3* 1111 1111 iph x0x0 0000 0b7h 0a8h ie* 00x0 0000 saddr 0000 0000 spsr 000x xx00 0afh 0a0h wdtrst (write-only) wdtcon 0000 x000 0a7h 98h scon* 0000 0000 sbuf xxxx xxxx 9fh 90h p1* 1111 1111 tconb 0010 0100 rl0 0000 0000 rl1 0000 0000 rh0 0000 0000 rh1 0000 0000 acsr xx00 0000 97h 88h tcon* 0000 0000 tmod 0000 0000 tl0 0000 0000 tl1 0000 0000 th0 0000 0000 th1 0000 0000 8fh 80h sp 0000 0111 dpl 0000 0000 dph 0000 0000 spdr xxxx xxxx pcon 000x 0000 87h
7 3547f?micro?6/06 at89lp2052/lp4052 7. comparison to standard 8051 the at89lp2052/lp4052 is part of a family of dev ices with enhanced features that are fully binary compatible with the mcs-51 instruction set. in addition, most sfr addresses, bit assign- ments, and pin alternate functions are identical to atmel's existing standard 8051 products. however, due to the high performance nature of the device, some system behaviors are differ- ent from those of atmel's standard 8051 products such as at89s52 or at89s2051. the differences from the standard 8051 are outlined in the following paragraphs. 7.1 system clock the cpu clock frequency equals the external xtal1 frequency. the oscillator is no longer divided by 2 to provide the internal clock, and x2 mode is not supported. 7.2 instruction execution with single-cycle fetch the cpu fetches one code byte from memory every clock cycle instead of every six clock cycles. this greatly increases the throughput of the cpu. as a consequence, the cpu no longer executes instructions in 12 to 48 clock cycles. each instruction executes in only 1 to 4 clock cycles. see section 21. ?instruction set summary? on page 49 for more details. 7.3 interrupt handling the interrupt controller polls the interrupt flags during the last clock cycle of any instruction. in order for an interrupt to be serviced at the end of an instruction, its flag needs to have been latched as active during the next to last clock cycl e of the instruction, or in the last clock cycle of the previous instruction if th e current instruction executes in only a single clock cycle. 7.4 timer/counters the timer/counters increment at a rate of once per clock cycle. this compares to once every 12 clocks in the standard 8051. 7.5 serial port the baud rate of the uart in mode 0 is 1/2 the clock frequency, compared to 1/12 the clock fre- quency in the standard 8051. in should also be noted that when using timer 1 to generate the baud rate in mode 1 or mode 3, the timer counts at the clock frequency and not at 1/12 the clock frequency. to maintain the same baud rate in the at89lp2052/lp4052 while running at the same frequency as a standard 8051, the time-out period must be 12 times longer. mode 1 of timer 1 supports 16-bit auto-r eload to facilitate longer time-o ut periods for generating low baud rates. 7.6 watchdog timer the watchdog timer in at89lp2052/lp4052 counts at a rate of once per clock cycle. this compares to once every 12 clocks in the standard 8051.
8 3547f?micro?6/06 at89lp2052/lp4052 7.7 i/o ports the i/o ports of the at89lp2052/lp4052 may be configured in four different modes. on the at89lp2052/lp4052, all the i/o ports revert to input-only (tri-stated) mode at power-up or reset. in the standard 8051, all ports are weakly pulled high during power-up or reset. to enable 8051- like ports, the ports must be put into quasi-bidirectional mode by clearing the p1m0 and p3m0 sfrs. 7.8 reset the rst pin in the at89lp2052/lp4052 has differ ent pulse width requirements than the stan- dard 8051. the rst pin is sampled every clock c ycle and must be held low for a minimum of two clock cycles, instead of 24 clock cycles, to be recognized as a valid reset pulse 8. enhanced cpu the at89lp2052/lp4052 uses an enhanced 8051 cpu that runs at 6 to 12 times the speed of standard 8051 devices (or 3 to 6 times the speed of x2-mode 8051 devices). the increase in performance is due to two factors. first, the cpu fetches one instruction byte from the code memory every clock cycle. second, the cpu uses a simple two-stage pipeline to fetch and exe- cute instructions in parallel. th is basic pipelining concept allows the cpu to obtain up to 1 mips per mhz. a simple example is shown in figure 8-1 . the mcs-51 instruction set allows for instructions of variable length from 1 to 3 bytes. in a sin- gle-clock-per-byte-fetch system this means each instruction takes at least as many clocks as it has bytes to execute. a majority of the instructions in the at89lp2052/lp4052 follow this rule: the instruction execution time in clock cycles equals the number of bytes per instruction with a few exceptions. branches and calls require an additional cycle to compute the target address and some other complex instructions require multiple cycles. see section 21. ?instruction set summary? on page 49 for more detailed information on individual instructions. figures 8-2 and 8-3 show examples of one- and two-byte instructions. figure 8-1. parallel instruction fetches and executions system clock n th instruction (n+1) th instruction fetch execute fetch execute fetch t n t n+1 t n+2 (n+2) th instruction
9 3547f?micro?6/06 at89lp2052/lp4052 figure 8-2. single-cycle alu operat ion (example: inc r0) figure 8-3. two-cycle alu operation (example: add a, #data ) system clock total execution time register operand fetch t 1 t 2 t 3 alu operation execute result write back fetch next instruction system clock total execution time fetch immediate operand t 1 t 2 t 3 alu operation execute result write back fetch next instruction
10 3547f?micro?6/06 at89lp2052/lp4052 9. restrictions on certain instructions the at89lp2052/lp4052 is an economical and cost-effective member of atmel's growing fam- ily of microcontrollers. it contains 2/4k bytes of flash program memory. it is fully compatible with the mcs-51 architecture, and can be programmed using the mcs-51 instruction set. however, there are a few considerations one must keep in mind when utilizing certain instructions to pro- gram this device. all the instruct ions related to jumping or branching should be restricted such that the destination address falls within the phys ical program memory space of the device, which is 2k bytes for the at89lp2052 and 4k bytes for the at89LP4052. this should be the responsi- bility of the software pr ogrammer. for example, ljmp 7e0h would be a valid instruction for the at89lp2052 (with 2k bytes of memory), whereas ljmp 900h would not. 9.1 branching instructions the lcall, ljmp, acall, ajmp, sjmp, and jmp @a+dptr unconditional branching instruc- tions will execute correctly as long as the programmer keeps in mind that the destination branching address must fall within the physical boundaries of the program memory size (loca- tions 000h to 7ffh for the at89lp2052, 000h to fffh for the at89LP4052). violating the physical space limits may cause unknown program behavior. with the cjne [...], djnz [...], jb, jnb, jc, jnc, jbc, jz, and jnz conditional branching instructions, the same previous rule applies. again, violating the memory boundaries may cause erratic execution. for applications involving interrupts, the normal interrupt service routine address locations of the 8051 family architecture have been preserved. 9.2 movx-related instru ctions, data memory external data memory access is not supported in this device, nor is external program mem- ory execution. therefore, no movx [...] instructions should be included in the program. a typical 8051 assembler will still assemble inst ructions, even if they are written in violation of the restric- tions mentioned above. it is the responsibility of the user to know the physical features and limitations of the device being used and to adjust the instructions used accordingly. 10. system clock the system clock is generated directly from on e of two selectable clock sources. the two sources are the on-chip crystal os cillator and external cl ock source. no intern al clock division is used to generate the cpu clock from the system clock. 10.1 crystal oscillator when enabled, the internal inverting oscillator amplifier is connected between xtal1 and xtal2 for connection to an external quartz crystal or ceramic resonator. when using the crystal oscillator, xtal2 should not be us ed to drive a board-level clock. 10.2 external clock source the external clock option is selected by setting the oscillator bypass fuse. this disables the amplifier and allows xtal1 to be driven dire ctly by the clock source. xtal2 may be left unconnected. 10.3 system clock out when the system clock out fuse is enabled, p3.7 will output the system clock with no division using the push-pull outpu t mode. during power-down the sys tem clock will output as ?1?.
11 3547f?micro?6/06 at89lp2052/lp4052 11. reset during reset, all i/o registers are set to their initial values, the port pins are tri-stated, and the program starts execution from the reset vector, 0000h. the at89lp2052/lp4052 has four sources of reset: power-on reset, brown-out reset, external reset, and watchdog reset. 11.1 power-on reset a power-on reset (por) is generated by an on-chip detection circuit. the detection level is nominally 1.4v. the por is activated whenever v cc is below the detection level. the por cir- cuit can be used to trigger the start-up reset or to detect a supply voltage failure in devices without a brown-out detector. the por circuit ens ures that the device is reset from power-on. when v cc reaches the power-on reset threshold voltage, the por delay counter determines how long the device is kept in por after v cc rise. the por signal is activated again, without any delay, when v cc falls below the por thre shold level. a power-on reset (i.e. a cold reset) will set the pof flag in pcon. 11.2 brown-out reset the at89lp2052/lp4052 has an on-chip brown-out detection (bod) circuit for monitoring the v cc level during operation by comparing it to a fixe d trigger level. the trig ger level for the bod is nominally 2.2v. the purpose of the bod is to ensure that if v cc fails or dips while executing at speed, the system will gracefully en ter reset without the possibility of errors induced by incorrect execution. when v cc decreases to a value below the trigger level, the brown-out reset is imme- diately activated. when v cc increases above the trigger level, the bod delay counter starts the mcu after the time-out period has expired. 11.3 external reset the rst pin functions as an active-high reset inpu t. the pin must be held high for at least two clock cycles to trigger the inte rnal reset. rst also serves as the in-system programming (isp) enable. isp is enabled when the external reset pin is held high and the isp enable fuse is enabled. 11.4 watchdog reset when the watchdog times out, it will generate an internal reset pulse lasting 16 clock cycles. watchdog reset will also set the wdtovf flag in wdtcon. to prevent a watchdog reset, the watchdog reset sequence 1eh/e1h must be written to wdtrst before the watchdog times out. a watchdog reset will occur only if the wa tchdog has been enabled. the watchdog is dis- abled by default after any reset and must always be re-enabled if needed. 12. power saving modes the at89lp2052/lp4052 supports two different power-reducing modes: idle and power-down. these modes are accessed through the pcon register.
12 3547f?micro?6/06 at89lp2052/lp4052 12.1 idle mode setting the idl bit in pcon enters idle mode. idle mode halts the internal cpu clock. the cpu state is preserved in its entirety, including the ram, stack pointer, program counter, program status word, and accumulator. the port pins hold the logic states they had at the time that idle was activated. idle mode leaves the peripherals running in order to allow them to wake up the cpu when an interrupt is generated. the timer, uart and spi blocks continue to function dur- ing idle. the comparator and watchdog may be selectively enabled or disabled during idle. any enabled interrupt source or reset may terminate idle mode. when exiting idle mode with an inter- rupt, the interrupt will immediately be serviced, and following reti the next instruction to be executed will be the one following the inst ruction that put the device into idle. 12.2 power-down mode setting the power-down (pd) bit in pcon enters power-down mode. power-down mode stops the oscillator and powers down th e flash memory in order to mi nimize power consumption. only the power-on circuitry will continue to draw power during power-down. during power-down, the power supply voltage may be r educed to the ram keep-alive vo ltage. the ram contents will be retained, but the sfr contents are not guaranteed once v cc has been reduced. power-down may be exited by external reset, power-on reset, or certain interrupts. the user should not attempt to enter (or re-enter) the power-down mode for a minimum of 4 s until after one of the following conditions has occurred: start of code execution (after any type of reset), or exit from power-down mode. 12.2.1 interrupt recovery from power-down two external interrupts may be configured to terminate power-down mode. pins p3.2 and p3.3 may be used to exit power-down through external interrupts int0 and int1 . to wake up by external interrupts int0 or int1 , that interrupt must be enabled and configured for level-sensi- tive operation. if configured as inputs, int0 and int1 should not be left floating during power- down even if interrupt recovery is not used. when terminating power-down by an interrupt, two different wake-up modes are available. when pwdex in pcon is zero, the wake-up period is internally timed. at the falling edge on the interrupt pin, power-down is exit ed, the oscillator is restarted, an d an internal timer begins count- ing. the internal clock will not be allowed to propagate to the cpu until after the timer has counted for nominally 2 ms. after the time-out period the interrup t service routine will begin. the interrupt pin may be held low until the device has timed out and begun executing, or it may return high before the end of the time-out period. if the pin remains low, the service routine should disable the interrupt before returning to avoid re-triggering the interrupt. when pwdex = ?1?, the wake-up period is controll ed externally by the interrupt. again, at the falling edge on the interrupt pin, power-down is exited and the oscillator is restarted. however, the internal clock will not propagate until the rising edge of the interrupt pi n. the interrupt should be held low long enough for the se lected clock source to stabilize. 12.2.2 reset exit from power-down the wake-up from power-down through an external reset is similar to the interrupt with pwdex = ?0?. at the risi ng edge of rst, power-down is exit ed, the oscillator is restarted, and an internal time r begins counting. the internal clock will no t be allowed to propagate to the cpu until after the timer has counted for nominally 2 ms. the rst pin must be held high for longer than the time-out period to ensure that the device is reset properly. the device will begin execut- ing once rst is brought back low.
13 3547f?micro?6/06 at89lp2052/lp4052 13. interrupts the at89lp2052/lp4052 provides 6 interrupt sources: two external interrupts, two timer inter- rupts, a serial port interrupt, and an analog comparator interrupt. these interrupts and the system reset each have a separate program vector at the st art of the program memory space. each interrupt source can be individually enabled or disabled by setting or clearing a bit in the interrupt enable register ie. the ie register also contains a global disable bit, ea, which disables all interrupts. each interrupt source can be individually programmed to one of four priority levels by setting or clearing bits in the interrupt priority registers ip and iph. an interrupt service routine in progress can be interrupted by a higher priority interrupt, but not by another interrupt of the same or lower priority. the highest priority interrupt cannot be interrupted by any other interrupt source. if two requests of different priority levels are pending at the end of an instruction, the request of higher priority level is serviced. if requests of the same priority level are pending at the end of an instruction, an internal polling sequence determines which request is serviced. the polling sequence is based on the vector address; an interrupt with a lower vector address has higher priority than an interrupt with a higher vector address. note that the polling sequence is only used to resolve pending requests of the same priority level. the external interrupts int0 and int1 can each be either level-activated or edge-activated, depending on bits it0 and it1 in register tcon. the flags that actually generate these inter- rupts are the ie0 and ie1 bits in tcon. when the service routine is vectored to, hardware clears the flag that generated an external interrupt only if the interrupt was edge-activated. if the inter- rupt was level activated, then the external requesting source (rather than the on-chip hardware) controls the request flag. table 12-1. pcon ? power control register pcon = 87h reset value = 000x 0000b not bit addressable smod1 smod0 pwdex pof gf1 gf0 pd idl bit76543210 symbol function smod1 double baud rate bit. doubles the baud rate of the uart in modes 1, 2, or 3. smod0 frame error select. when smod0 = 1, scon.7 is sm0. when smod0 = 1, scon.7 is fe. note that fe will be set after a frame error regardless of the state of smod0. pwdex power-down exit mode. when pwdex = 1, wake up from power-down is extern ally controlled. when pwdex = 0, wake up from power-down is internally timed. pof power off flag. pof is set to ?1? during power up (i.e. cold reset). it can be set or reset under software control and is no t affected by rst or bod (i.e. warm resets). gf1, gf0 general-purpose flags pd power-down bit. setting this bi t activates power-down operation. idl idle mode bit. setting this bit activates idle mode operation
14 3547f?micro?6/06 at89lp2052/lp4052 the timer 0 and timer 1 interrupts are generated by tf0 and tf1, which are set by a rollover in their respective timer/counter registers (except for timer 0 in mode 3). when a timer interrupt is generated, the on-chip hardware clears the flag that generated it when the service routine is vectored to. the serial port interrupt is generated by the logi c or of ri and ti in scon plus spif in spsr. none of these flags is cleared by hardware when the service routine is vectored to. in fact, the service routine normally must determine whether ri, ti, or spif generated the interrupt, and the bit must be cleared by software. the cf bit in acsr generates the comparator interrupt. the flag is not cleared by hardware when the service routine is vectored to and must be cleared by software. most of the bits that generate interrupts can be set or cleared by software, with the same result as though they had been set or cleared by hardware. that is, interrupts can be generated and pending interrupts can be canceled in software. t he exception is the spi interrupt flag spif. this flag is only set by hardware and may only be cleared by software. 13.1 interrupt response time the interrupt flags may be set by their hardware in any clock cycle. the interrupt controller polls the flags in the last clock cycle of the instruction in progress. if one of the flags was set in the preceding cycle, the polling cycl e will find it and the interrupt system will generate an lcall to the appropriate service routine as the next instruct ion, provided that the interrupt is not blocked by any of the following conditions: an interrupt of equal or higher priority level is already in progress; the instruction in progress is reti or any write to the ie, ip, or iph registers. either of these conditions will block the gene ration of the lcall to the inte rrupt service routine. the sec- ond condition ensures that if the instruction in progress is reti or any access to ie, ip or iph, then at least one more instruction will be executed before any interrupt is vectored to. the poll- ing cycle is repeated at the last cycle of each instruction, and the values polled are the values that were present at the previous clock cycle. if an active interrupt flag is not being serviced because of one of the above conditions and is no longer active when the blocking condition is removed, the denied interrupt will not be serviced. in other words, the fact that t he interrupt flag was once active but not serviced is no t remembered. every polling cycle is new. if a request is active and conditions are met fo r it to be acknowledged, a hardware subroutine call to the requested service routine will be the next instruction executed. the call itself takes four cycles. thus, a minimum of five complete clock cycles elapsed between activation of an interrupt request and the beginning of execution of the first instruction of the service routine. table 13-1. interrupt vector addresses interrupt source vector address system reset rst or por or bod 0000h external interrupt 0 ie0 0003h timer 0 overflow tf0 000bh external interrupt 1 ie1 0013h timer 1 overflow tf1 001bh serial port ri or ti or spif 0023h reserved ? 002bh analog comparator cf 0033h
15 3547f?micro?6/06 at89lp2052/lp4052 a longer response time results if the request is blocked by one of the previously listed condi- tions. if an interrupt of equal or higher priority le vel is already in progress, the additional wait time depends on the nature of the other interrupt's service routine. if the instruction in progress is not in its final clock cycle, the additional wait time cannot be more than 3 cycles, since the longest are only 4 cycles long. if the instruction in progres s is reti or an access to ie or ip, the addi- tional wait time cannot be more than 7 cycles (a maximum of three more cycles to complete the instruction in progress, plus a maximum of 4 cycles to complete the next instruction). thus, in a single-interrupt system, the re sponse time is always more th an 5 clock cycles and less than 13 clock cycles. see figures 13-1 and 13-2 . figure 13-1. minimum interrupt response time figure 13-2. maximum interrupt response time clock cycles int0 ie0 15 instruction lcall 1st isr instr. cur. instr. ack. clock cycles int0 ie0 113 instruction reti 4 cyc. instr. lcall 1st isr i n ack.
16 3547f?micro?6/06 at89lp2052/lp4052 table 13-2. ie ? interrupt enable register ie = a8h reset value = 00x0 0000b bit addressable ea ec ? es et1 ex1 et0 ex0 bit76543210 symbol function ea global enable/disable. all interrupts are disabled when ea = 0. when ea = 1, each interr upt source is enabled/disabled by setting /clearing its own enable bit. ec comparator interrupt enable es serial port interrupt enable et1 timer 1 interrupt enable ex1 external interrupt 1 enable et0 timer 0 interrupt enable ex0 external interrupt 0 enable table 13-3. ip ? interrupt priority register ip = b8h reset value = x0x0 0000b bit addressable ? pc ? ps pt1 px1 pt0 px0 bit76543210 symbol function pc comparator interrupt priority low ps serial port interrupt priority low pt1 timer 1 interrupt priority low px1 external interrupt 1 priority low pt0 timer 0 interrupt priority low px0 external interrupt 0 priority low
17 3547f?micro?6/06 at89lp2052/lp4052 14. i/o ports all 15 port pins on the at89lp2052/lp4052 may be configured to one of four modes: quasi-bidi- rectional (standard 8051 port outputs), push-pull output, open-drain output, or input-only. port modes may be assigned in software on a pin-by-pin basis as shown in table 14-1 . all port pins default to input-only mode after reset. each port pin also has a schmitt-triggered input for improved input noise rejection. during power-down all the schmitt-triggered inputs are disabled with the exception of p3.2 and p3.3, which may be used to wake-up the device. therefore p3.2 and p3.3 should not be left floating during power-down. 14.1 quasi-bidirectional output port pins in quasi-bidirectional output mode function similar to standard 8051 port pins. a quasi- bidirectional port can be used both as an input and output without the need to reconfigure the port. this is possible because when the port out puts a logic high, it is weakly driven, allowing an external device to pull the pin low. when the pi n is driven low, it is driven strongly and able to sink a large current. there are three pull-up transistors in the quasi-bidirectional output that serve different purposes. one of these pull-ups, called the ?very weak? pull-up, is turned on whenever the port register for the pin contains a logic ?1?. this very weak pull-up sources a ve ry small current that will pull the pin high if it is left floating. a second pull-up, called the ?weak? pull-up, is turned on when the port register for the pin con- tains a logic ?1? and the pin itself is also at a logic ?1? level. this pull- up provides the primary source current for a quasi-bidirectional pin that is outputting a 1. if this pin is pulled low by an table 13-4. iph ? interrupt priority high register iph = b7h reset value = x0x0 0000b not bit addressable ? pch ? psh pt1h px1h pt0h px0h bit76543210 symbol function pch comparator interrupt priority high psh serial port interrupt priority high pt1h timer 1 interrupt priority high px1h external interrupt 1 priority high pt0h timer 0 interrupt priority high px0h external interrupt 0 priority high table 14-1. configuration modes for port x, bit y pxm0.y pxm1.y port mode 0 0 quasi-bidirectional 0 1 push-pull output 1 0 input only (high impedance) 1 1 open-drain output
18 3547f?micro?6/06 at89lp2052/lp4052 external device, this weak pull-up turns off, and only the very weak pull-up remains on. in order to pull the pin low under these conditions, the external device has to sink enough current to over- power the weak pull-up and pull the port pin below its input threshold voltage. the third pull-up is referred to as the ?strong? pull-up. this pull-up is used to speed up low-to- high transitions on a quasi-bidirectional port pin when the port register changes from a logic ?0? to a logic ?1?. when this occurs , the strong pull-up turns on for one cpu clock, quickly pulling the port pin high. when in quasi-bidirectional mode the port pin will always output a ?0? when corresponding bit in the port register is also ?0?. when the port regi ster is ?1? the pin may be used either as an input or an output of ?1?. the quasi-bidirectional port configuration is shown in figure 14-1 . the input circuitry of p3.2 and p3.3 is not disabled during power-down (see figure 14-3 ). figure 14-1. quasi-bidirectional output 14.2 input-only mode the input port configuration is shown in figure 14-2 . it is a schmitt-triggered input for improved input noise rejection. figure 14-2. input only figure 14-3. input only for p3.2 and p3.3 1 clock delay (d flip-flop) strong ver y weak weak port pin v cc v cc v cc from port register input data pwd port pin input data pwd port pin input data
19 3547f?micro?6/06 at89lp2052/lp4052 14.3 open-drain output the open-drain output configuration turns off all pull-ups and only drives the pull-down transistor of the port pin when the port register contains a logic ?0?. to be used as a logic output, a port configured in this manner must have an external pull-up, typically a resistor tied to v cc . the pull- down for this mode is the same as for the quasi-bidirectional mode. the open-drain port configu- ration is shown in figure 14-4 . the input circuitry of p3.2 and p3.3 is not disabled during power- down (see figure 14-3 ). figure 14-4. open-drain output 14.4 push-pull output the push-pull output configuration has the same pull-down structure as both the open-drain and the quasi-bidirectional output modes, but prov ides a continuous strong pull-up when the port register contains a logic ?1?. the push-pull mode may be used when more source current is needed from a port output. the push-pull port configuration is shown in figure 14-5 . the input circuitry of p3.2 and p3.3 is not disabled during power-down (see figure 14-3 ). figure 14-5. push-pull output 14.5 port 1 analog functions the at89lp2052/lp4052 incorporates an analog comparator. in order to give the best analog performance and minimize power consumption, pins that are being used for analog functions must have both the digital outputs and digital inpu ts disabled. digital outputs are disabled by put- ting the port pins into the input-only mode as described in section 14. ?i/o ports? on page 17 . digital inputs on p1.0 and p1.1 are disabled whenever the analog comparator is enabled by setting the cen bit in acsr. cen forces the pwd input on p1.0 and p1.1 low, thereby disabling the schmitt trigger circuitry. port pin from port register input data pwd port pin v cc from port register input data pwd
20 3547f?micro?6/06 at89lp2052/lp4052 14.6 port read-modify-write a read from a port will read either the state of the pins or the st ate of the port register depending on which instruction is used. simple read instruct ions will always access t he port pins directly. read-modify-write instruct ions, which read a value, possibly mo dify it, and then write it back, will always access the port register. this includes bit write instructions such as clr or setb as they actually read the entire port, modify a single bit, then write the data back to the entire port. see table 14-2 for a complete list of read-modify-write instruction which may access the ports. 14.7 port alternate functions most general-purpose digital i/o pins of the at89lp2052/lp4052 share functionality with the various i/os needed for the peripheral units. table 14-4 lists the alternate functions of the port pins. alternate functions are connected to the pins in a logic and fashion. in order to enable the alternate function on a port pin, that pin must have a ?1? in its corresponding port register bit, oth- erwise, the input/outpu t will always be ?0?. furthermore , each pin must be configured for the correct input/output mode as required by its peripheral before it may be used as such. table 14-3 shows how to configure a generic pin for use with an alternate function. table 14-2. port read-modify- write instructions mnemonic instruction example anl logical and anl p1, a orl logical or orl p1, a xrl logical ex-or xrl p1, a jbc jump if bit set and clear bit jbc p3.0, label cpl complement bit cpl p3.1 inc increment inc p1 dec decrement dec p3 djnz decrement and jump if not zero djnz p3, label mov px.y, c move carry to bit y of port x mov p1.0, c clr px.y clear bit y of port x clr p1.1 setb px.y set bit y of port x setb p3.2 table 14-3. alternate function configurations for pin y of port x pxm0.y pxm1.y px.y i/o mode 0 0 1 bidirectional (internal pull-up) 011output 1 0 x input 1 1 1 bidirectional (external pull-up)
21 3547f?micro?6/06 at89lp2052/lp4052 15. enhanced timer/counters the at89lp2052/lp4052 has two 16-bit timer/counter registers: timer 0 and timer 1. as a timer, the register is incremented every clock cycle. thus, the register counts clock cycles. since a clock cycle consists of one oscillator period, the count rate is e qual to the oscillator frequency. as a counter, the register is incremented in re sponse to a 1-to-0 transition at its corresponding input pin, t0 or t1. the external input is sampled every clock cycle. when the samples show a high in one cycle and a low in the next cycle, the count is incremented. the new count value appears in the register during the cycle following the one in which the transition was detected. since 2 clock cycles are required to recognize a 1-to-0 transition, the maximum count rate is 1/2 of the oscillator frequency. there are no restrictions on the duty cycle of the input signal, but it should be held for at least one full clock cycle to ensure that a given level is sampled at least once before it changes. furthermore, the timer or counter functions for timer 0 and timer 1 have four operating modes: variable width timer/counter, 16 bit auto-reload timer/counter, 8 bit auto-reload timer/counter, and split timer/counter. the control bits c/t in the special function register tmod select the timer or counter function. the bit pairs (m1, m0) in tmod select the operating modes. 15.1 mode 0 both timers in mode 0 are 8-bit counters with a variable prescaler. the prescaler may vary from 1 to 8 bits depending on the psc bits in tconb, giving the timer a range of 9 to 16 bits. by default the timer is configured as a 13-bit timer compatible to mode 0 in the standard 8051. figure 15-1 shows the mode 0 operation as it applies to timer 1 in 13-bit mode. as the count rolls over from all ?1?s to all ?0?s, it sets the timer interrupt flag tf1. the counted input is enabled to the timer when tr1 = 1 and either gate = 0 or int1 = 1. setting gate = 1 allows the timer to be controlled by external input int1 , to facilitate pulse width measurements. tr1 is table 14-4. port pin alternate functions port pin configuration bits alternate function notes pxm0.y pxm1.y p1.0 p1m0.0 p1m1.0 ain0 input-only p1.1 p1m0.1 p1m1.1 ain1 input-only p1.4 p1m0.4 p1m1.4 ss refer to section 18.4 ?spi pin configuration? on page 45 p1.5 p1m0.5 p1m1.5 mosi p1.6 p1m0.6 p1m1.6 miso p1.7 p1m0.7 p1m1.7 sck p3.0 p3m0.0 p3m1.0 rxd p3.1 p3m0.1 p3m1.1 txd p3.2 p3m0.2 p3m1.2 int0 p3.3 p3m0.3 p3m1.3 int1 p3.4 p3m0.4 p3m1.4 t0 refer to section 15.6 ?timer/counter pin configuration? on page 27 p3.5 p3m0.5 p3m1.5 t1 p3.6 not configurable cmpout pin is tied to comparator output
22 3547f?micro?6/06 at89lp2052/lp4052 a control bit in the special function register tc on. gate is in tmod. the 13-bit register con- sists of all 8 bits of th1 and the lower 5 bits of tl1. the upper 3 bits of tl1 are indeterminate and should be ignored. setting the run flag (tr1) does not clear the registers. see figure 15-1 . figure 15-1. timer/counter 1 mode 0: variable width counter mode 0 operation is the same for timer 0 as for timer 1, except that tr0, tf0 and int0 replace the corresponding timer 1 signals in figure 15-1 . there are two different gate bits, one for timer 1 (tmod.7) and one for timer 0 (tmod.3). 15.2 mode 1 in mode 1 the timers are configured for 16-bit auto-reload. the timer register is run with all 16 bits. the 16-bit reload value is stored in the hi gh and low reload registers (rh1/rl1). the clock is applied to the combined high and low timer registers (th1/tl1). as clock pulses are received, the timer counts up: 0000h, 000 1h, 0002h, etc. an overflow occurs on the ffffh-to-0000h transition, upon which the timer register is reloaded with the value from rh1/rl1 and the over- flow flag bit in tcon is set. see figure 15-2 . the reload registers default to 0000h, which gives the full 16-bit timer period compatible with the standard 8051. mode 1 operation is the same for timer/counter 0. figure 15-2. timer/counter 1 mode 1: 16-bit auto-reload osc t1 pin tr1 gate int1 pin tl1 (8 bits) control interrupt c/t = 0 c/t = 1 psc1 th1 (8 bits) tf1 osc t1 pin tr1 gate int1 pin tl1 (8 bits) control interrupt c/t = 0 c/t =1 th1 (8 bits) tf1 rl1 (8 bits) rh1 (8 bits) reload
23 3547f?micro?6/06 at89lp2052/lp4052 15.3 mode 2 mode 2 configures the timer register as an 8-bi t counter (tl1) with automatic reload, as shown in figure 15-3 . overflow from tl1 not only sets tf1, but also reloads tl1 with the contents of th1, which is preset by software. the reload leaves th1 unchanged. mode 2 operation is the same for timer/counter 0. figure 15-3. timer/counter 1 mode 2: 8-bit auto-reload 15.4 mode 3 timer 1 in mode 3 simply holds its count. the effe ct is the same as setting tr1 = 0. timer 0 in mode 3 establishes tl0 and th0 as two separate counters. the logic for mode 3 on timer 0 is shown in figure 15-4 . tl0 uses the timer 0 control bits: c/t , gate, tr0, int0 , and tf0. th0 is locked into a timer function (counting machine cycles) and take s over the use of tr1 and tf1 from timer 1. thus, th0 now controls the timer 1 interrupt. mode 3 is for applications requiring an extra 8-bi t timer or counter. with timer 0 in mode 3, the at89lp2052/lp4052 can appear to have three timer/counters. when timer 0 is in mode 3, timer 1 can be turned on and off by switching it out of and into its own mode 3. in this case, timer 1 can still be used by the serial port as a baud rate generator or in any application not requiring an interrupt. figure 15-4. timer/counter 0 mode 3: two 8-bit counters osc t1 pin tr1 gate tf1 tl1 (8 bits) th1 (8 bits) control reload interrupt int0 pin c/t = 0 c/t = 1 control interr u pt control interr u pt ( 8 bit s ) ( 8 bit s ) c/t = 0 c/t =1 t0 pin gate int0 pin
24 3547f?micro?6/06 at89lp2052/lp4052 table 15-1. tcon ? timer/counter control register tmod = 88h reset value = 0000 0000b not bit addressable tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 bit7 6543210 symbol function tf1 timer 1 overflow flag. set by hardware on timer/counter overflow. cleared by hardware when the processor vectors to interrupt routine. tr1 timer 1 run control bit. set/cleared by software to turn ti mer/counter on/off. tf0 timer 0 overflow flag. set by hardware on timer/counter overflow. cleared by hardware when the processor vectors to interrupt routine. tr0 timer 0 run control bit. set/cleared by software to turn ti mer/counter on/off. ie1 interrupt 1 flag. when it1 is set, ie1 is set by hardware when the external interrupt falling edge is detected, and is clear ed by hardware when the cpu vectors to the interrupt routine. when it1 is cleared, ie1 is sampled and inverted from the external interrupt pin. the flag will be set or cleared by hardware depending on the state of p3.3. it1 interrupt 1 type control bit. set/clea red by software to specify falling edge/low level triggered external interrupts. ie0 interrupt 0 flag. when it0 is set, ie0 is set by hardware when the external interrupt falling edge is detected, and is clear ed by hardware when the cpu vectors to the interrupt routine. when it0 is cleared, ie0 is sampled and inverted from the external interrupt pin. the flag will be set or cleared by hardware depending on the state of p3.2. it0 interrupt 0 type control bit. set/clea red by software to specify falling edge/low level triggered external interrupts.
25 3547f?micro?6/06 at89lp2052/lp4052 . . table 15-2. tmod: timer/counter mode control register tmod = 89h reset value = 0000 0000b not bit addressable gate c/t m1 m0 gate c/t m1 m0 76 5432 10 timer1 timer0 gate gating control: when set timer/counter x is enabled only while intx pin is high and trx control pin is set. when cleared, timer x is enabled whenever trx control bit is set. timer 0 gate bit timer 0 counter/timer select bit c/t timer or counter selector: cleared for timer operation (input from internal system clock). set for counter operation (input from tx input pin). timer 0 m1 bit timer 0 m0 bit m1 mode bit 1 m0 mode bit 0 m1 m0 mode operating mode 000variable 9 - 16-bit timer/c ounter. 8-bit timer/counter thz with tlx as 1 - 8-bit prescaler. 0 1 1 16-bit auto reload timer/counter. 8-bit timer/counters thx and tlx are cascaded; there is no prescaler. 1028-bit auto reload timer/counter. 8-bit auto-reload timer/counter thx holds a value which is to be reloaded into tlx each time it overflows. 113split timer/c ounter. (timer 0) tl0 is an 8-bit timer/counter controlled by the standard timer 0 control bits. th0 is an 8-bit timer only controlled by timer 1 control bits. 113(timer 1) timer/counter 1 st opped. timer sfr purpose address bit-addressable tcon control 88h yes tmod mode 89h no tl0 timer 0 low-byte 8ah no tl1 timer 1 low-byte 8bh no th0 timer 0 high-byte 8ch no th1 timer 1 high-byte 8dh no tconb mode 91h no rl0 timer 0 reload low-byte 92h no rl1 timer 1 reload low-byte 93h no rh0 timer 0 reload high-byte 94h no rh1 timer 1 reload high-byte 95h no
26 3547f?micro?6/06 at89lp2052/lp4052 15.5 pulse width modulation timer 0 and timer 1 may be independently configured as 8-bit asymmetrical pulse width modu- lators (pwm) by setting the pwm0en or pwm1en bits in tconb, respectively. in pwm mode the generated waveform is output on the timer's pin, t0 or t1. c/t must be set to ?0? when in pwm mode. in timer 0's pwm mode, th0 acts as an 8-bit counter while rh0 stores the 8-bit compare value. when th0 is 00h the pwm output is set high. when the th0 count reaches the value stored in rh0 the pwm output is set low. therefore, the pulse width is proportional to the value in rh0. to prevent glitches writes to rh 0 only take effect on the ffh to 00h overflow of th0. timer 1 has the same b ehavior using th1 and rh1. see figure 15-5 for pwm waveform example. setting rh0 to 00h will keep the pwm output low. the pwm will only function if the timer is in mode 0 or mode 1. in mode 0, tl0 acts as a logarith- mic prescaler driving th0 (see figure 15-6 ). the psc0 bits in tconb control the prescaler value. in mode 1, tl0 provides linear prescaling with an 8-bit auto-reload from rl0 (see figure 15-7 ). figure 15-5. asymmetrical pulse width modulation table 15-3. tconb ? timer/counter control register b tconb = 91h reset value = 0010 0100b not bit addressable pwm1en pwm0en psc12 psc11 psc10 psc02 psc01 psc00 bit7 6543210 symbol function pwm1en configures timer 1 for pulse widt h modulation output on t1 (p3.5). pwm0en configures timer 0 for pulse widt h modulation output on t0 (p3.4). psc12 psc11 psc10 prescaler for timer 1 mode 0. the number of active bits in tl1 equals psc1 + 1. after reset psc1 = 100b which enables 5 bits of tl1 for compatibility with the 13-bit mode 0 in at89s2051. psc02 psc01 psc00 prescaler for timer 0 mode 0. the number of active bits in tl0 equals psc0 + 1. after reset psc0 = 100b which enables 5 bits of tl0 for compatibility with the 13-bit mode 0 in at89c52. pwm output (t0) counter value (th0) compare value (rh0)
27 3547f?micro?6/06 at89lp2052/lp4052 figure 15-6. timer/counter 1 pwm mode 0 figure 15-7. timer/counter 1 pwm mode 1 15.6 timer/counter pi n configuration in order to use the counter input function or pulse width modulation output feature of timer 0 or timer 1, the timer pins t0 (p3.4) and t1 (p3.5) must be configured appropriately. see section 14.7 ?port alternate functions? on page 20 . for the external counter input function, t0 or t1 should be configured as input-only, or as bidirectional with p3.4 or p3.5 set to ?1?. the counter function may also be triggered by an internal event if t0 or t1 is configured in a bidirectional or output mode and the port bit is toggled accordingly. to enable a pwm output on t0 or t1, the pin must be configured in a bidirectional or output mode with p3.4 or p3.5 set to ?1?. setting the pwm0en or pwm1en bits in tconb will not automatically configure the pins as outputs. the pwm outputs will use a full cmos push -pull driver if they are in th e quasi-bidirectional or output configurations. 16. external interrupts the int0 and int1 external interrupt sources can be programmed to be level-activated or tran- sition-activated by setting or clearing bit it1 or it0 in register tcon. if itx = 0, external interrupt x is triggered by a detected low at the intx pin. if itx = 1, external interrupt x is nega- tive edge-triggered. in this mode if successive samples of the intx pin show a high in one cycle osc tr1 gate int1 pin tl1 (8 bits) control psc1 th1 (8 bits) ocr1 rh1 (8 bits) = t1 osc tr1 gate int1 pin tl1 (8 bits) control th1 (8 bits) ocr1 rh1 (8 bits) = t1 rl1 (8 bits)
28 3547f?micro?6/06 at89lp2052/lp4052 and a low in the next cycle, interrupt request flag iex in tcon is set. flag bit iex then requests the interrupt. since the external interrupt pins are sampled once each clock cycle, an input high or low should hold for at least 2 oscillator periods to ensure sampling. if the external interrupt is transition-activated, the external source has to hold the request pin high for at least two clock cycles, and then hold it low for at least two clock cycles to ensure that the transition is seen so that interrupt req uest flag iex will be set. iex will be auto matically cleared by the cpu when the service routine is called if generated in edge-triggered mode. if the external interrupt is level-acti- vated, the external source has to hold the request active until the requested interrupt is actually generated. then the external source must deactivate the request before the interrupt service routine is completed, or else another inte rrupt will be generated. 17. serial interface the serial port is full-duplex, which means it can transmit and receive simultaneously. it is also receive-buffered, which means it can begin receiving a second byte before a previously received byte has been read from the re ceive register. (however, if the first byte still ha s not been read when reception of the second byte is complete, the first byte will be lost.) the serial port receive and transmit registers are both accessed at special function register sbuf. writing to sbuf loads the transmit register, and reading sbuf acce sses a physically separate receive register. the serial port can operate in the following four modes. mode 0: half-duplex serial data enters or exits thro ugh rxd. txd outputs th e shift clock. eight data bits are transmitted/received, with the lsb fi rst. the baud rate is fixed at 1/2 the oscillator frequency. mode 1: 10 bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on receive, the stop bit goes into rb8 in special function register scon. the baud rate is variable based on timer 1 overflow. mode 2: 11 bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), a programmable ninth data bit, and a stop bit (1). on transmit, the 9th data bit (tb8 in scon) can be assigned the value of ?0? or ?1?. for example, the parity bit (p, in the psw) can be moved into tb8. on receive, the 9th data bit goes into rb8 in special function register scon, while the stop bi t is ignored. the baud rate is programmable to either 1/16 or 1/32 the oscillator frequency. mode 3: 11 bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), a programmable ninth data bit, and a stop bit (1). in fact, mode 3 is the same as mode 2 in all respects except the baud rate, which in mode 3 is variable based on timer 1 overflow. in all four modes, transmission is initiated by any instruction that uses sbuf as a destination register. reception is initiated in mode 0 by the condition ri = 0 and ren = 1. reception is initi- ated in the other modes by the incoming start bit if ren = 1. 17.1 multiprocessor communications modes 2 and 3 have a special provision for mult iprocessor communications. in these modes, 9 data bits are received, followed by a stop bit. the ninth bit goes into rb8. then comes a stop bit. the port can be programmed such that when the stop bit is received, the serial port interrupt is activated only if rb8 = 1. this feature is enabled by setting bit sm2 in scon. the following example shows how to use the serial interrupt for multiprocessor communications. when the master processor must transmit a block of data to one of several slaves, it first sends
29 3547f?micro?6/06 at89lp2052/lp4052 out an address byte that identifies the target slave. an address byte differs from a data byte in that the 9th bit is ?1? in an address byte and ?0? in a data byte. with sm2 = 1, no slave is inter- rupted by a data byte. an address byte, however, interrupts all slaves, so that each slave can examine the received byte and see if it is be ing addressed. the addressed slave clears its sm2 bit and prepares to receive the data bytes that follows. the slaves that are not addressed set their sm2 bits and ignore the data bytes. the sm2 bit has no effect in mode 0 but can be used to check the validity of the stop bit in mode 1. in a mode 1 reception, if sm2 = 1, the receive interrupt is not activated unless a valid stop bit is received. notes: 1. smod0 is located at pcon.6. 2. f osc = oscillator frequency. table 17-1. scon ? serial port control register scon address = 98h reset value = 0000 0000b bit addressable sm0/fe sm1 sm2 ren tb8 rb8 t1 ri bit7 6543210 (smod0 = 0/1) (1) symbol function fe framing error bit. this bit is set by the receiver when an in valid stop bit is detected. the fe bit is not cleared by valid frames but should be cleared by software. the smod0 bit must be set to enable access to the fe bit. fe will be set regardless of the state of smod0. sm0 serial port mode bit 0, (smod0 must = 0 to access bit sm0) sm1 serial port mode bit 1 sm2 enables the automatic address recognition feature in modes 2 or 3. if sm2 = 1 then rl will not be set unless the received 9th data bit (rb8) is 1, indicating an address, and the received byte is a given or broadcast address. in mode 1, if sm2 = 1 then rl will not be activated unless a valid stop bit was receiv ed, and the received byte is a given or broadcast address. in mode 0, sm2 should be 0. ren enables serial reception. set by software to enable reception. clear by software to disable reception. tb8 the 9th data bit that will be transmitted in modes 2 and 3. set or clear by software as desired. rb8 in modes 2 and 3, the 9th data bit that was received. in mode 1, if sm2 = 0, rb8 is the stop bit that was received. in mode 0, rb8 is not used. ti transmit interrupt flag. set by hardware at the end of the 8th bit time in mode 0, or at the beginning of the stop bit in the other modes, in any serial transmission. must be cleared by software. ri receive interrupt flag. set by hardware at the end of the 8th bit time in mode 0, or halfway through the stop bit time in the other modes, in any serial reception (except see sm2). must be cleared by software. sm0 sm1 mode description baud rate (2) 0 0 0 shift register f osc /2 0 1 1 8-bit uart variable 1 0 2 9-bit uart f osc /32 or f osc /16 1 1 3 9-bit uart variable
30 3547f?micro?6/06 at89lp2052/lp4052 17.2 baud rates the baud rate in mode 0 is fixed as shown in the following equation. the baud rate in mode 2 depends on the value of the smod1 bit in special function register pcon.7. if smod1 = 0 (the value on reset), the baud rate is 1/32 of the oscillator frequency. if smod1 = 1, the baud rate is 1/16 of the oscillator frequ ency, as shown in th e following equation. 17.2.1 using timer 1 to generate baud rates the timer 1 overflow rate determines the baud rates in modes 1 and 3. when timer 1 is the baud rate generator, the baud rates are determined by the timer 1 overflow rate and the value of smod1 according to the following equation. the timer 1 interrupt should be disabled in this application. the timer itself can be configured for either timer or counter operation in any of its 3 running modes. in the most typical applica- tions, it is configured for timer operation in auto-reload mode (high nibble of tmod = 0010b). in this case, the baud rate is given by the following formula. programmers can achieve very low baud rates with timer 1 by configuring the timer to run as a 16-bit auto-reload timer (high nibble of tmod = 0001b). in this case, the baud rate is given by the following formula. mode 0 baud rate oscillator frequency 2 ------------------------------------------------------ - = mode 2 baud rate 2 smod1 32 -------------------- (oscillator frequency) = 2 smod1 32 -------------------- (timer 1 overflow rate) = modes 1, 3 baud rate 2 smod1 32 -------------------- oscillator frequency 256 th1 () ? [] ------------------------------------------------------ - = modes 1, 3 baud rate 2 smod1 32 -------------------- oscillator frequency 65536 rh1,rl1 () ? [] -------------------------------------------------------- - = modes 1, 3 baud rate
31 3547f?micro?6/06 at89lp2052/lp4052 table 17-2 lists commonly used baud rates and how they can be obtained from timer 1. 17.3 more about mode 0 serial data enters and exits through rxd. txd outputs the shift clock. eight data bits are trans- mitted/received, with the lsb first. the baud rate is fixed at 1/2 the osc illator frequency. figure 17-1 shows a simplified functional diagram of the serial port in mode 0 and associated timing. transmission is initiated by any instruction that uses sbuf as a destination register. the ?write to sbuf? signal also loads a ?1? into the ninth position of the transmit shift register and tells the tx control block to begin a transmission. the inte rnal timing is such that one full machine cycle will elapse between ?write to sbuf? and activation of send. send transfers the output of the shift register to the alternate output function line of p3.0, and also transfers shift clock to the al ternate output function line of p3.1. at t he falling edge of shift clock the contents of the transmit shift register are shifted one position to the right. as data bits shift out to the right, ?0?s come in from the left. when the msb of the data byte is at the output position of the shift register, the ?1? that was initially loaded into the ninth position is just to the left of the msb, and all positions to the left of that contain ?0?s. this condition flags the tx control block to do one last shift, then deactivate send and set ti. reception is initiated by the cond ition ren = 1 and r1 = 0. at the next clock cycle, the rx con- trol unit writes the bits 11111110 to the receive shift register and activates receive in the next clock phase. receive enables shift clock to th e alternate output fu nction line of p3.1. at the falling edge of shift clock the contents of the receive shift register are shifted one position to the left. the value that comes in from the right is the value that was sampled at the p3.0 pin at rising edge of shift clock. as data bits come in from the right, ?1?s shift out to the left. when the ?0? that was initially loaded into the right-most position arrives at the left-most position in the shift register, it flags the rx control block to do one last shift and load sbu f. then receive is cl eared and ri is set. table 17-2. commonly used baud rates generated by timer 1 baud rate f osc (mhz) smod1 timer 1 c/t mode reload value mode 0: 1 mhz 2 x x x x mode 2: 375k 12 0 x x x 62.5k 12 102 f4h 19.2k 11.059 1 0 2 dch 9.6k 11.059 0 0 2 dch 4.8k 11.059 0 0 2 b8h 2.4k 11.059 0 0 2 70h 1.2k 11.059 0 0 1 fee0h 137.5 11.986 0 0 1 f55ch 110 6 0 0 1 f958h 110 12 0 0 1 f304h
32 3547f?micro?6/06 at89lp2052/lp4052 figure 17-1. serial port mode 0 internal bus 1/2 f osc internal bus txd (shift clock) rxd (data out) txd (shift clock) rxd (data in) write to sbuf send shift ti write to scon (clear ri) shift receive ri ?1?
33 3547f?micro?6/06 at89lp2052/lp4052 17.4 more about mode 1 ten bits are transmitted (through txd), or receiv ed (through rxd): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on receive, the stop bit goes into rb8 in scon. in the at89lp2052/lp4052, the baud rate is determined by the timer 1 overflow rate. the baud rate is determined by the timer 1 overflow rate. figure 17-2 shows a simplified functional diagram of the serial port in mode 1 and associated timings for transmit and receive. transmission is initiated by any instruction that uses sbuf as a destination register. the ?write to sbuf? signal also loads a ?1? into the ninth bit position of the transmit shift register and flags the tx control unit that a tran smission is requested. transmission actually commences at s1p1 of the machine cycle following the next rollover in the divide-by-16 counter. thus, the bit times are synchronized to the divide-by-16 counter, not to the ?write to sbuf? signal. the transmission begins when send is activated, which puts the start bit at txd. one bit time later, data is activated, which enables the output bit of the transmit shift register to txd. the first shift pulse occurs one bit time after that. as data bits shift out to the right, ?0?s are clock ed in from the left. when the msb of the data byte is at the output position of the shift register, the ?1? that was initially loaded into the ninth position is just to the left of the msb, and all positions to the left of that contain ?0?s. this condition flags the tx control unit to do one last shift, then deactivate send and set ti. this occurs at the tenth divide-by-16 rollover after ?write to sbuf.? reception is initiated by a 1-to-0 transition detected at rxd. for this purpose, rxd is sampled at a rate of 16 times the established baud rate. when a transition is detected, the divide-by-16 counter is immediately reset, and 1ffh is written into the input shift register. resetting the divide-by-16 counter aligns its roll-overs with the boundaries of the incoming bit times. the 16 states of the counter divide each bit time into 16ths. at the seventh, eighth, and ninth counter states of each bit time, the bit detector samples the value of rxd. the value accepted is the value that was seen in at least 2 of the 3 samples. this is done to reject noise. in order to reject false bits, if the value accepted during the first bit time is not 0, the receive circuits are reset and the unit continues looking for another 1-to-0 transition. if the start bit is valid, it is shifted into the input shift register, and reception of the rest of the frame proceeds. as data bits come in from the right, ?1?s shift out to the left. when the start bit arrives at the left most position in the shift register, (which is a 9-bit register in mode 1), it flags the rx control block to do one last shift, load sbuf and rb8, and set ri. the signal to load sbuf and rb8 and to set ri is generated if, and only if, the following conditions are met at the time the final shift pulse is generated. ri = 0 and either sm2 = 0, or the received stop bit = 1 if either of these two conditions is not met, the received frame is irretrievably lost. if both condi- tions are met, the stop bit goes into rb8, the 8 data bits go into sbuf, and ri is activated. at this time, whether or not the above conditions are met, the unit continues looking for a 1-to-0 transition in rxd.
34 3547f?micro?6/06 at89lp2052/lp4052 figure 17-2. serial port mode 1 tx clock write to sbuf internal bus read sbuf load sbuf sbuf shift input shift reg. (9 bits) bit detector 1-to-0 transition detector serial port interrupt write to sbuf 2 smod1 = 0 smod1 = 1 timer 1 overflow rxd rx clock rx clock rx control start start data send sample 16 16 tx control ti t i zero detector sbuf txd internal bus ?1? d q cl s load sbuf shift shift 1ffh ri send data shift txd ti d0 d1 d2 d3 d4 d5 d6 d7 d0 d1 d2 d3 d4 d5 d6 d7 stop bit transmit start bit 16 reset start bit stop bit rx clock bit detector sample times shift receive rxd ri
35 3547f?micro?6/06 at89lp2052/lp4052 17.5 more about modes 2 and 3 eleven bits are transmitted (through txd), or re ceived (through rxd): a start bit (0), 8 data bits (lsb first), a programmable ninth data bit, and a stop bit (1). on transmit, the ninth data bit (tb8) can be assigned the value of ?0? or ?1?. on receive, the ninth data bit goes into rb8 in scon. the baud rate is programmable to either 1/16 or 1/32 of the oscillator frequency in mode 2. mode 3 may have a variable baud rate generated from timer 1. figures 17-3 and 17-4 show a functional diagram of the serial port in modes 2 and 3. the receive portion is exactly the same as in mode 1. the transmit portion differs from mode 1 only in the ninth bit of the transmit shift register. transmission is initiated by any instruction that uses sbuf as a destination register. the ?write to sbuf? signal also loads tb8 into the ninth bi t position of the transmit shift register and flags the tx control unit that a transmission is requested. transmission commences at s1p1 of the machine cycle following the next ro llover in the divide-by-16 counter. thus, the bit times are syn- chronized to the divide-by-16 counter, not to the ?write to sbuf? signal. the transmission begins when send is activated, which puts the start bit at txd. one bit time later, data is activated, which enables the output bit of the transmit shift register to txd. the first shift pulse occurs one bit time after that. the first shift clocks a ?1? (the stop bit) into the ninth bit position of the shift register. thereafter, only ?0 ?s are clocked in. thus, as data bits shift out to the right, ?0?s are clocked in from the left. when tb8 is at the output position of the shift register, then the stop bit is just to the left of tb8, and all positions to the left of that contain ?0?s. this con- dition flags the tx control unit to do one last shift, then deactivate send and set ti. this occurs at the 11th divide-by-16 rollover after ?write to sbuf.? reception is initiated by a 1-to-0 transition detected at rxd. for this purpose, rxd is sampled at a rate of 16 times the established baud rate. when a transition is detected, the divide-by-16 counter is immediately reset, and 1ffh is written to the input shift register. at the seventh, eighth and ninth counter states of each bit time, the bit detector samples the value of rxd. the value accepted is the value that was seen in at least 2 of the 3 samples. if the value accepted during the first bit time is not 0, the receive circuits are reset and the unit contin- ues looking for another 1-to-0 transition. if the start bit proves valid, it is shifted into the input shift register, and reception of the rest of the frame proceeds. as data bits come in from the right, ?1?s shift out to the left. when the start bit arrives at the left most position in the shift register (which in modes 2 and 3 is a 9-bit register), it flags the rx con- trol block to do one last shift, load sbuf and rb8, and set ri. the signal to load sbuf and rb8 and to set ri is generated if, and only if, the following conditions are met at the time the final shift pulse is generated: ri = 0, and either sm2 = 0 or the received 9th data bit = 1 if either of these conditions is not met, the received frame is irretrievably lost, and ri is not set. if both conditions are met, the received ninth data bit goes into rb8, and the first 8 data bits go into sbuf. one bit time later, whether the above conditions were met or not, the unit continues looking for a 1-to-0 transition at the rxd input. note that the value of the received stop bit is irrelevant to sbuf, rb8, or ri.
36 3547f?micro?6/06 at89lp2052/lp4052 figure 17-3. serial port mode 2 smod1 1 smod1 0 internal bus internal bus cpu clock
37 3547f?micro?6/06 at89lp2052/lp4052 figure 17-4. serial port mode 3 tx clock write to sbuf send data shift txd stop bit gen ti d0 d1 d2 d3 d4 d5 d6 d7 tb8 stop bit transmit start bit internal bus read sbuf load sbuf sbuf shift input shift reg. (9 bits) bit detector 1-to-0 transition detector serial port interrupt write to sbuf 2 smod1 = 0 smod1 = 1 timer 1 overflow rxd rx clock rx clock rx control start start data sample 16 16 tx control ti zero detector sbuf txd internal bus tb8 d q cl s load sbuf shift 1ffh shift ri send d0 d1 d2 d3 d4 d5 d6 d7 rb8 start bit stop bit 16 reset rx clock bit detector sample times shift receive rxd ri stop bit
38 3547f?micro?6/06 at89lp2052/lp4052 17.6 framing error detection when used for framing error detect, the uart lo oks for missing stop bits in the communication. a missing bit will set the fe bit in the scon regi ster. the fe bit shares the scon.7 bit with sm0 and the function of scon.7 is determined by pcon.6 (smod0). if smod0 is set then scon.7 functions as fe. scon.7 f unctions as sm0 when smod0 is cleared. when used as fe, scon.7 can only be cleared by software. 17.7 automatic ad dress recognition automatic address recognition is a feature wh ich allows the uart to recognize certain addresses in the serial bit stream by using hardware to make the comparisons. this feature saves a great deal of software overhead by eliminating the need for the software to examine every serial address which passes by the serial port. this feature is enabled by setting the sm2 bit in scon. in the 9-bit uart modes, mode 2 and mode 3, the receive interrupt flag (ri) will be automatically set when the received byte cont ains either the ?given? address or the ?broad- cast? address. the 9-bit mode requires that the 9th information bit is a ?1? to indicate that the received information is an address and not data. the 8-bit mode is called mode 1. in this mode the ri flag will be set if sm2 is enabled and the information received has a valid stop bit following the 8 address bits and the information is either a given or broadcast address. mode 0 is the shift register mode and sm2 is ignored. using the automatic address recognition feature allows a master to selectively communicate with one or more slaves by invoking the given slav e address or addresses. all of the slaves may be contacted by using the broadcast address. two special function registers are used to define the slave?s address, saddr, and the address mask, saden. saden is used to define which bits in the saddr are to be used and which bits are ?don?t care?. the saden mask can be logically anded with the saddr to create th e ?given? address which the master will use for addressing each of the slaves. use of the given address allows multiple slaves to be recognized while excluding others. th e following examples will help to show the versatility of this scheme: slave 0 saddr = 1100 0000 saden = 1111 1101 given = 1100 00x0 slave 1 saddr = 1100 0000 saden = 1111 1110 given = 1100 000x in the previous example saddr is the same and the saden data is used to differentiate between the two slaves. slave 0 requ ires a ?0? in bit 0 and it ignores bit 1. slave 1 requires a ?0? in bit 1 and bit 0 is ignored. a unique address for slave 0 would be 1100 0010 since slave 1 requires a ?0? in bit 1. a unique address for sl ave 1 would be 1100 0001 since a ?1? in bit 0 will exclude slave 0. both slaves can be selected at the same time by an address which has bit 0 = 0 (for slave 0) and bit 1 = 0 (for slave 1). thus, both could be addressed with 1100 0000. in a more complex system the following could be used to select slaves 1 and 2 while excluding slave 0:
39 3547f?micro?6/06 at89lp2052/lp4052 slave 0 saddr = 1100 0000 saden = 1111 1001 given = 1100 0xx0 slave 1 saddr = 1110 0000 saden = 1111 1010 given = 1110 0x0x slave 2 saddr = 1110 0000 saden = 1111 1100 given = 1110 00xx in the above example the differentiation among the 3 slaves is in the lower 3 address bits. slave 0 requires that bit 0 = 0 and it can be uniquely addressed by 1110 0110. slave 1 requires that bit 1 = 0 and it can be uniquely addressed by 1110 and 0101. slave 2 requires that bit 2 = 0 and its unique address is 1110 0011. to select slaves 0 and 1 and exclude slave 2, use address 1110 0100, since it is necessary to ma ke bit 2 = 1 to exclude slave 2. the broadcast address for each slave is created by taking t he logic or of saddr and saden. zeros in this result are treated as don?t cares. in most cases, interpreting the don?t cares as ones, the broadcast address will be ff hexadecimal. upon reset saddr (sfr address 0a9h) and saden (sfr address 0b9h) are loaded with ?0?s. this produces a given address of all ?don?t cares? as well as a broadcast address of all ?don?t cares?. this effectively disables the automatic addressing mode and allows the microcon- troller to use standard 80c51-type uart drivers which do not make use of this feature. 18. serial peripheral interface the serial peripheral interface (spi) allows high-speed synchronous data transfer between the at89lp2052/lp4052 and peripheral devices or between multiple at89lp2052/lp4052 devices. the at89lp2052/lp4052 spi features include the following:  full-duplex, 3-wire synchronous data transfer  master or slave operation  maximum bit frequency = f/4  lsb first or msb first data transfer  four programmable bit rates in master mode  end of transmission interrupt flag  write collision flag protection  double-buffered receive  double-buffered transmit (enhanced mode only)  wake up from idle mode (slave mode only) the interconnection between master and slave cpus with spi is shown in figure 18-1 . the four pins in the interface are master-in/slave-out (miso), master-out/slave-in (mosi), shift clock
40 3547f?micro?6/06 at89lp2052/lp4052 (sck), and slave select (ss ). the sck pin is the clock output in master mode, but is the clock input in slave mode. the mstr bit in spcr determines the directions of miso and mosi. also notice that mosi connects to mosi and miso to miso. in master mode, ss /p1.4 is ignored and may be used as a general-purpose input or output. in slave mode, ss must be driven low to select an individual device as a slave. when ss is driven high, the slave?s spi port is deacti- vated and the mosi/p1.5 pin can be used as a general-purpose input. figure 18-1. spi master-slave interconnection figure 18-2. spi block diagram 8 -bit s hift regi s ter 8 -bit s hift regi s ter m as ter clock gener a tor s pi mi s o s l a ve mi s o mo s imo s i s ck s ck ss ss v cc m s bl s b m s bl s b o s cill a tor 8 - b it s hift regi s ter re a d d a t a b u ffer pin control logic s pi control s pi s t a t us regi s ter s pi interr u pt req u e s t intern a l d a t a b us s elect s pi clock (m a ter) divider 4 8 3 264 s pi control regi s ter 8 8 8 s pif wcol s pr1 m s tr s pie clock logic clock m s b s m s pe dord m s tr cpol cpha s pr1 s pr0 m s tr s pe dord l s b s m m s mi s o p1.6 mo s i p1.5 s ck 1.7 ss p1.4 s pr0 s pe write d a t a b u ffer
41 3547f?micro?6/06 at89lp2052/lp4052 18.1 normal mode the spi has two modes of operation: normal (non-buffered write) and enhanced (buffered write). in normal mode, writing to the spi data register (spdr) of the master cpu starts the spi clock generator and the data written shifts out of the mosi pin and into the mosi pin of the slave cpu. transmission may start after an initial delay while the clock generator waits for the next full bit slot of the specified baud rate. after shifti ng one byte, the spi clock generator stops, setting the end of transmission flag (spif) and transferring the received byte to the read buffer (spdr). if both the spi interrupt enable bit (spie) and the serial port interrupt enable bit (es) are set, an interrupt is requested. note that spdr refers to either the write data buffer or the read data buffer, depending on whether the access is a write or read. in normal mode, because the write buffer is transparent (and a writ e access to spdr will be directed to the shift buffer ), any attempt to write to spdr while a transmission is in progre ss will result in a write collision with wcol set. however, the transmission will still complete norma lly, but the new byte will be ignored and a new write access to spdr will be necessary. 18.2 enhanced mode enhanced mode is similar to normal mode except that the write buffer holds the next byte to be transmitted. writing to spdr loads the write buffer and sets wcol to signify that the buffer is full and any further writes will over write the buffer. wcol is cleare d by hardware when the buff- ered byte is loaded into the shift register and transmission begins. if the master spi is currently idle, i.e. if this is the first byte, then afte r loading spdr, transmission of the byte starts and wcol is cleared immediately. while this byte is transmitting, the next byte may be written to spdr. the load enable flag (lden) in spsr ca n be used to determin e when transmission has started. lden is asserted during the first four bit slots of a spi transfer. the master cpu should first check that lden is set and that wcol is cleared before loading the next byte. in enhanced mode, if wcol is set when a transfer completes, i.e. the next byte is available, then the spi immediately loads the buffered byte into the sh ift register, resets wcol, and continues trans- mission without stopping and restarting the clock generator. as long as the cpu can keep the write buffer full in this manner, multiple bytes may be transferred with minimal latency between bytes.
42 3547f?micro?6/06 at89lp2052/lp4052 notes: 1. set up the clock mode before enabling the spi: set all bits needed in spcr except the spe bit, then set spe. 2. enable the master spi prior to the slave device. 3. slave echoes master on the next tx if not loaded with new data. table 18-1. spcr ? spi control register spcr address = d5h reset value = 0000 0000b not bit addressable spie spe dord mstr cpol cpha spr1 spr0 bit76543210 symbol function spie spi interrupt enable. this bit, in conjunction with the es bit in the ie register, enables spi interrupts: spie = 1 and es = 1 enable spi interrupts. spie = 0 disables spi interrupts. spe spi enable. spi = 1 enables the spi channel and connects ss , mosi, miso and sck to pins p1.4, p1.5, p1.6, and p1.7. spi = 0 disables the spi channel. dord data order. dord = 1 selects lsb first data tran smission. dord = 0 selects ms b first data transmission. mstr master/slave select. mstr = 1 selects mast er spi mode. mstr = 0 selects slave spi mode. cpol clock polarity. when cpol = 1, sck is high when idle. when cpol = 0, sck of the master device is low when not transmitting. please refer to figure on spi clock phase and polarity control. cpha clock phase. the cpha bit together wit h the cpol bit controls the clock and data relationship between master and slave. please refer to figure on spi clock phase and polarity control. spr0 spr1 spi clock rate select. these two bits c ontrol the sck rate of the device configured as master. spr1 and spr0 have no effect on the slave. the relationship between sck and the oscillator frequency, f osc. , is as follows: spr1 spr0 sck 00 f/4 01 f/8 10 f/32 11 f/64
43 3547f?micro?6/06 at89lp2052/lp4052 table 18-2. spsr ? spi status register spsr address = aah reset value = 000x x000b not bit addressable spif wcol lden ? ? ? disso enh bit76543210 symbol function spif sp interrupt flag. when a serial transfer is complete, the spif bit is set and an interrupt is generated if spie = 1 and es = 1. the spif bit is cleared by reading the spi status re gister followed by reading/writing the spi data register. wcol when enh = 0: write collision flag. the wcol bit is set if th e spi data register is written during a data transfer. during data transfer, the result of reading the spdr register may be incorrect, and writing to it has no effect. the wcol bit (and the spif bit) are cleared by reading the spi status r egister followed by reading/writ ing the spi data register. when enh = 1: wcol works in enhanced mode as tx buff er full. writing during wcol = 1 in enhanced mode will overwrite the waiting data already present in the tx buffer. in this mode, wcol is no longer reset by the spif reset but is reset when the write buffer has been unloaded into the serial shift register. lden load enable for the tx buffer in enhanced spi mode. when enh is set, it is safe to load the tx buffer while lden = 1 and wcol = 0. lden is high during bits 0 - 3 and is low during bits 4 - 7 of the spi serial byte transmission time frame. disso disable slave output bit. when set, this bit causes the miso pin to be tri-stated so more than one slave device can share the same interface with a single master. normally, the first byte in a transmission could be the slave address and only the selected slave should clear its disso bit. enh enhanced spi mode select bit. when enh = 0, spi is in normal mode, i.e. without write double buffering. when enh = 1, spi is in enhanced mode with write double buff ering. the tx buffer shares the same address with the spdr register. table 18-3. spdr ? spi data register spdr address = 86h reset value = 00h (after cold reset) unchanged (after warm reset) not bit addressable spd7 spd6 spd5 spd4 spd3 spd2 spd1 spd0 bit76543210
44 3547f?micro?6/06 at89lp2052/lp4052 figure 18-3. spi shift register diagram 18.3 serial clock generator the cpha (c lock pha se), cpol (c lock pol arity), and spr (s erial p eripheral clock r ate = baud rate) bits in spcr control the shape and rate of sck. the two spr bits provide four possi- ble clock rates when the spi is in master mode. in sl ave mode, the spi will op erate at the rate of the incoming sck as long as it does not exceed the maximum bit rate. there are also four pos- sible combinations of sck phase and polarity with respect to the serial data. cpha and cpol determine which format is used for transmission. the spi data transfer formats are shown in figures 18-4 and and 18-5 . to prevent glitches on sck from disrupting the interface, cpha, cpol, and spr should be set up before the interface is enabled, and the master device should be enabled before the slave device(s). 2:1 mux 2:1 mux serial master serial slave latch dq clk latch dq clk latch dq clk latch dq clk parallel slave (read buffer) parallel master (write buffer) serial out receive byte serial in transmit byte 8 8 8 8 7 8
45 3547f?micro?6/06 at89lp2052/lp4052 figure 18-4. spi transfer format with cpha = 0 note: *not defined but normally msb of character just received figure 18-5. spi transfer format with cpha = 1 note: *not defined but normally lsb of previously transmitted character 18.4 spi pin configuration before using the serial peripheral interface the four spi pins ? sck, miso, mosi and ss ? must be properly configured for the desired functionality. see section 14.7 ?port alternate func- tions? on page 20 . when the spi is in master mode, sck and mosi must be configured as bidirectional or output, with p1.7 and p1.5 set to ?1?. miso should be input-only, or bidirectional with p1.6 set to ?1?. when the spi is in slave mode, sck, mo si and ss must be configured as input-only, or as bidirectional with p1.7, p1.6 and p1.4 set to ?1?. miso should be set as bidirec- tional or output, with p1.6 set to ?1?. if all four pins are set as bidirectional and their respectively port bits are all ?1?, it is possible to switch between master and slave mode without reconfiguring the pins. msb 6 5 4 3 2 1 lsb 1 2 3 4 5 6 7 8 msb * 65432 1 lsb sck cycle # (for reference) sck (cpol = 0) sck (cpol = 1) mosi (from master) miso (from slave) ss (to slave)
46 3547f?micro?6/06 at89lp2052/lp4052 19. analog comparator a single analog comparator is provided on the at89lp2052/lp4052. comparator operation is such that the output is a logic ?1? when the positive input ain0 (p1.0) is greater than the negative input ain1 (p1.1). otherwise, the output is a zero. setting the cen bit in acsr enables the comparator. when the comparator is first enabled, the comparator output and interrupt flag are guaranteed to be stable only after 10 s. the corresponding comparator interrupt should not be enabled during that time, and the comparator interrupt flag must be cleared before the interrupt is enabled in order to prevent an immediate interrupt service. before enabling the comparator the analog inputs should be tri-stated by putting p1.0 and p1.1 into input-only mode. see sec- tion 14.5 ?port 1 analog functions? on page 19 . the comparator output is internally tied to the p3.6 pin. instructions which read the pins of p3 will also read the com parator output directly. re ad-modify-write instructi ons or write instructions to p3.6 will access bit 6 of the port 3 register without affecting t he comparator. the comparator may be configured to cause an interrupt under a variety of output value condi- tions by setting the cm bits in acsr. the compar ator interrupt flag cf in acsr is set whenever the comparator output matches the condition specified by cm. the flag may be polled by soft- ware or may be used to generate an interrupt and must be cleared by software. the ec bit in ie must be set before cf will generate an interrupt. 19.1 comparator inte rrupt with debouncing the comparator output is sampled every clock cycl e. the conditions on the analog inputs may be such that the comparator outpu t will toggle excessively. this is especially true if applying slow moving analog inputs. three debouncing modes are pr ovided to filter out this noise. in debounc- ing mode, the comparator uses timer 1 to modulate its sampling time. when a relevant transition occurs, the comparator waits until two timer 1 overflows have occurred before resam- pling the output. if the new sample agrees with the expected value, cf is set. otherwise the event is ignored. the filter may be tuned by adjusting the time-out period of timer 1. because timer 1 is free running, the debouncer must wait for two overflows to guarantee that the sam- pling delay is at least 1 time-out period. therefore after the initial edge event, the interrupt may occur between 1 and 2 time-out periods later. see figure 19-1 . by default the comparator is disabled during id le mode. to allow the comparator to function dur- ing idle, the cidl bit in acsr must be set. when cidl is set, the comparator can be used to wake-up the cpu from idle if the comparator interrupt is enabled. the comparator is always dis- abled during power-down mode. figure 19-1. negative edge with debouncing example comparator out timer 1 overflow cf start compare start compare
47 3547f?micro?6/06 at89lp2052/lp4052 table 19-1. acsr ? analog comparator control & status register acsr = 97h reset value = xxx0 0000b not bit addressable ?? cidl cf cen cm2 cm1 cm0 bit76543210 symbol function cidl comparator idle enable. if cidl = 1 the comparator will continue to operate during idle mode. if cidl = 0 the comparator is powered down during idle mode. the com parator is always shut down during power-down mode. cf comparator interrupt flag. set when the comparator output meets the conditions specified by the cm [2:0] bits and cen is set. the flag must be cleared by software. the interrup t may be enabled/disabled by setting/clearing bit 6 of ie. cen comparator enable. set this bit to enable the comparator. clearing this bit will force the comparator output low and prevent further events from setting cf. cm [2:0] comparator interrupt mode 2 1 0 interrupt mode 000negative (low) level 001positive edge 010toggle with debounce 011positive edge with debounce 100negative edge 101toggle 110negative edge with debounce 111positive (high) level
48 3547f?micro?6/06 at89lp2052/lp4052 20. programmable watchdog timer the programmable watchdog time r (wdt) protects the system from incorrect execution by trig- gering a system reset when it times out after the software has failed to feed the timer prior to the timer overflow. the wdt counts cpu clock cycles. the prescaler bits, ps0, ps1 and ps2 in sfr wdtcon are used to set the period of the watchdog timer from 16k to 2048k clock cycles. the wdt is disabled by reset and duri ng power-down mode. when the wdt times out without being serviced, an internal rst pul se is generated to reset the cpu. see table 20-1 for the available wdt period selections. note: *the wdt time-out period is dependent on the system clock frequency. the watchdog timer consists of a 14-bit timer wi th 7-bit programmable prescaler. writing the sequence 1eh/e1h to the wdtrst register enables the timer. when the wdt is enabled, the wdten bit in wdtcon will be se t to ?1?. to preven t the wdt from generating a reset when if overflows, the watchdog feed sequence must be written to wdtrst before the end of the time- out period. to feed the watchdog, two write instructions must be sequentially executed success- fully. between the two write instructions, sfr read s are allowed, but writes are not allowed. the instructions should move 1eh to the wdtrst register and then 1eh to the wdtrst register. an incorrect feed or enable s equence will cause an immediate watchdog reset. the program sequence to feed or enable the watchdog timer is as follows: mov wdtrst, #01eh mov wdtrst, #0e1h table 20-1. watchdog timer time-out period selection wdt prescaler bits period* (clock cycles) ps2 ps1 ps0 000 16k 001 32k 010 64k 011 128k 100 256k 101 512k 1 1 0 1024k 1 1 1 2048k
49 3547f?micro?6/06 at89lp2052/lp4052 s 21. instruction set summary the at89lp2052/lp4052 is fully binary compatible with the mcs-51 instruction set. the difference between the at89lp2052/lp4052 and the standard 8051 is the number of cycles required to execute an instruction. instructions in the at89lp2052/lp4052 may take 1, 2, 3 or 4 clock cycles to complete. the execution times of most instructions may be computed using table 21-1 . table 20-2. wdtcon ? watchdog control register wdtcon address = a7h reset value = 0000 xx00b not bit addressable ps2 ps1 ps0 wdidle ? ? wdtovf wdten bit76543210 symbol function ps2 ps1 ps0 prescaler bits for the watchdog timer (wdt). when all thr ee bits are cleared to 0, the watchdog timer has a nominal period of 16k clock cycles. when all three bits are set to 1, the nominal period is 2048k clock cycles. wdidle disable/enable the watchdog timer in idle mode. when wdidle = 0, wdt continues to count in idle mode. when wdidle = 1, wdt freezes while the device is in idle mode. wdtovf watchdog overflow flag. set when a wdt reset is generated by the wdt timer overflow. also set when an incorrect sequence is written to wdtrst. must be cleared by software. wdten watchdog enable flag. this bit is read-only and reflects the status of the wdt (whether it is running or not). the wdt is disabled after any reset and must be re-enabled by writing 1eh/e1h to wdtrst table 20-3. wdtrst ? watchdog reset register wdtcon address = a6h (write-only) not bit addressable ???????? bit76543210 the wdt is enabled by writing the sequence 1eh/e1h to the wdtrst sfr. the current status may be checked by reading the wdten bit in wdtcon. to prevent the wdt from resetti ng the device, the same sequence 1eh/e1h must be written to wdtrst before the time-out interval expires.
50 3547f?micro?6/06 at89lp2052/lp4052 table 21-1. generic instruction execution times and exceptions instruction type cycle count most arithmetic, logical, bit and transfer instructions # bytes branches and calls # bytes + 1 single byte indirect (i.e. add a, @ri, etc.) 2 ret, reti 4 movc 3 mul 2 div 4 inc dptr 2 table 21-2. detailed arithmetic instruction summary arithmetic instruction bytes clock cycles hex code 8051 lp2052 add a, rn 1 12 1 28-2f add a, direct 2 12 2 25 add a, @ri 1 12 2 26-27 add a, #data 2 12 2 24 addc a, rn 1 12 1 38-3f addc a, direct 2 12 2 35 addc a, @ri 1 12 2 36-37 addc a, #data 2 12 2 34 subb a, rn 1 12 1 98-9f subb a, direct 2 12 2 95 subb a, @ri 1 12 2 96-97 subb a, #data 2 12 2 94 inc rn 1 12 1 08-0f inc direct 2 12 2 05 inc @ri 1 12 2 06-07 inc a 1 12 1 04 dec rn 1 12 1 18-1f dec direct 2 12 2 15 dec @ri 1 12 2 16-17 dec a 1 12 1 14 inc dptr 1 24 2 a3 mul ab 1 48 2 a4 div ab 1 48 4 84 da a 1 12 1 d4
51 3547f?micro?6/06 at89lp2052/lp4052 table 21-3. detailed logical instruction summary logical instruction bytes clock cycles hex code 8051 lp2052 clr a 1 12 1 e4 cpl a 1 12 1 f4 anl a, rn 1 12 1 58-5f anl a, direct 2 12 2 55 anl a, @ri 1 12 2 56-57 anl a, #data 2 12 2 54 anl direct, a 2 12 2 52 anl direct, #data 3 24 3 53 orl a, rn 1 12 1 48-4f orl a, direct 2 12 2 45 orl a, @ri 1 12 2 46-47 orl a, #data 2 12 2 44 orl direct, a 2 12 2 42 orl direct, #data 3 24 3 43 xrl a, rn 1 12 1 68-6f xrl a, direct 2 12 2 65 xrl a, @ri 1 12 2 66-67 xrl a, #data 2 12 2 64 xrl direct, a 2 12 2 62 xrl direct, #data 3 24 3 63 rl a 1 12 1 23 rlc a 1 12 1 33 rr a 1 12 1 03 rrc a 1 12 1 13 swap a 1 12 1 c4
52 3547f?micro?6/06 at89lp2052/lp4052 table 21-4. detailed data transfer instruction summary data transfer instruction bytes clock cycles hex code 8051 lp2052 mov a, rn 1 12 1 e8-ef mov a, direct 2 12 2 e5 mov a, @ri 1 12 2 e6-e7 mov a, #data 2 12 2 74 mov rn, a 1 12 1 f8-ff mov rn, direct 2 24 2 a8-af mov rn, #data 2 12 2 78-7f mov direct, a 2 12 2 f5 mov direct, rn 2 24 2 88-8f mov direct, direct 3 24 3 85 mov direct, @ri 2 24 2 86-87 mov direct, #data 3 24 3 75 mov @ri, a 1 12 1 f6-f7 mov @ri, direct 2 24 2 a6-a7 mov @ri, #data 2 12 2 76-77 mov dptr, #data16 3 24 3 90 movc a, @a+dptr 1 24 3 93 movc a, @a+pc 1 24 3 83 push direct 2 24 2 c0 pop direct 2 24 2 d0 xch a, rn 1 12 1 c8-cf xch a, direct 2 12 2 c5 xch a, @ri 1 12 2 c6-c7 xchd a, @ri 1 12 2 d6-d7
53 3547f?micro?6/06 at89lp2052/lp4052 table 21-5. detailed bit instruction summary bit instruction bytes clock cycles hex code 8051 lp2052 clr c 1 12 1 c3 clr bit 2 12 2 c2 setb c 1 12 1 d3 setb bit 2 12 2 d2 cpl c 1 12 1 b3 cpl bit 2 12 2 b2 anl c, bit 2 24 2 82 anl c, /bit 2242b0 orl c, bit 2 24 2 72 orl c, /bit 2242a0 mov c, bit 2 12 2 a2 mov bit, c 2 24 2 92 table 21-6. detailed branching instruction summary branching instruction bytes clock cycles hex code 8051 lp2052 jc rel 224340 jnc rel 2 24 3 50 jb bit, rel 3 24 4 20 jnb bit, rel 3 24 4 30 jbc bit, rel 3 24 4 10 jz rel 224360 jnz rel 224370 sjmp rel 2 24 3 80 acall addr11 2 24 3 11,31,51,7 1,91,b1,d1 ,f1 lcall addr16 3 24 4 12 ret 124422 reti 124432 ajmp addr11 2 24 3 01,21,41,6 1,81,a1,c1 ,e1 ljmp addr16 3 24 4 02 jmp @a+dptr 1 24 2 73 cjne a, direct, rel 3 24 4 b5 cjne a, #data, rel 3 24 4 b4 cjne rn, #data, rel 3 24 4 b8-bf cjne @ri, #data, rel 3 24 4 b6-b7 djnz rn, rel 2 24 3 d8-df djnz direct, rel 3 24 4 d5 nop 112100
54 3547f?micro?6/06 at89lp2052/lp4052 22. programming the flash memory the at89lp2052/lp4052 offers 2/4k bytes of in-system programmable (isp) non-volatile flash code memory. in addition, the device contains a 32-byte user signature row and a 32-byte read-only atmel signature row. the memory organization is shown in table 22-1 . the memory is divided into pages of 32 bytes each. a single read or write command may only access a single page in the memory. the at89lp2052/lp4052 provides two flexible in terfaces for programming the flash memory: a parallel interface which uses 10 pins; and a seri al interface which uses the 4 spi pins. isp and serial programming are identical. both interfaces support the same command format where each command is issued to the device one byte at a time. commands consist of a preamble byte for noise immunity, an opcode byte, two address bytes, and from 1 to 32 data bytes. figure 22-1 shows a simplified flow chart of a command sequence. figure 22-1. command sequence flow chart table 22-1. memory organization device # code size page size # pages address range at89lp2052 2k bytes 32 bytes 64 0000h - 07ffh at89LP4052 4k bytes 32 bytes 128 0000h - 0fffh input preamble (aah) input opcode input address high byte input address low byte input/output data address +1
55 3547f?micro?6/06 at89lp2052/lp4052 notes: 1. program enable must be the first command issued after entering into programming mode. 2. any number of data bytes from 1 to 32 may be written/re ad. the internal address is incremented between each byte. 3. fuse bit definitions : * the at89lp2052/lp4052 has isp enabled by default from the fact ory. however, if isp is later disabled, the isp enable fuse must be enabled by using parallel programming before entering isp mode. when disabling the isp fuse during isp, the current i sp session will remain active until rst is brought low. 4. lock bit definitions : 5. atmel signature byte : 6. symbol key : 22.1 programming command summary command preamble opcode addr high addr low data 0 data n program enable (1) 1010 1010 1010 1100 0101 0011 chip erase 1010 1010 1000 1010 read status 1010 1010 0110 0000 xxxx xxxx xxxx xxxx status out load code page buffer (2) 1010 1010 0101 0001 xxxx xxxx xxx da tain 0 ... datain n write code page (2) 1010 1010 0101 0000 xxxx data in 0 ... datain n read code page (2) 1010 1010 0011 0000 xxxx data out 0 ... dataout n write user fuses (3) 1010 1010 1110 0001 xxxx xxxx xxxx xxxx xxxx read user fuses (3) 1010 1010 0110 0001 xxxx xxxx xxxx xxxx xxxx write lock bits (4) 1010 1010 1110 0100 xxxx xxxx xxxx xxxx xxxx xx read lock bits (4) 1010 1010 0110 0100 xxxx xxxx xxxx xxxx xxxx xx write user signature page (2) 1010 1010 0101 0010 xxxx xxxx xxx da tain 0 ... datain n read user signature page (2) 1010 1010 0011 0010 xxxx xxxx xxx da taout 0 ... dataout n read atmel signature page (2)(5) 1010 1010 0011 1000 xxxx xxxx xxx da taout 0 ... dataout n bit 0 bit 1 bit 2 bit 3 isp enable * xtal osc bypass user row programming system clock out enable = 0/disable = 1 enable = 0/disable = 1 enable = 0/disable = 1 enable = 0/disable = 1 bit 0 bit 1 lock bit 1 lock bit 2 locked = 0/unlocked = 1 locked = 0/unlocked = 1 at89lp2052: address 00h = 1eh 01h = 25h 02h = ffh at89LP4052: address 00h = 1eh 01h = 45h 02h = ffh a: page address bit b: byte address bit f: fuse bit data l: lock bit data x: don?t care a11 a10 a9 a8 a7 a6 a5 b4 b3 b2 b1 b0 a11 a10 a9 a8 f3 f2 f1 f0 f3 f2 f1 f0 l1 l0 l1 l0 a7 a6 a5 b4 b3 b2 b1 b0 b4 b3 b2 b1 b0 b4 b3 b2 b1 b0 b4 b3 b2 b1 b0 b4 b3 b2 b1 b0
56 3547f?micro?6/06 at89lp2052/lp4052 22.2 status register the current state of the memory may be accessed by reading the status register. the status reg- ister is shown in table 22-2 . 22.3 data polling the at89lp2052/lp4052 implements data polling to indicate the end of a programming cycle. while the device is busy, any atte mpted read of th e last byte written will re turn the data byte with the msb complement ed. once the programm ing cycle has completed, the true value will be accessible. during erase the data is assumed to be ffh and data polling will return 7fh. when writing multiple bytes in a page, the data value will be the last data byte loaded before programming begins, not the written byte with the highest physical address within the page. 22.4 parallel programming parallel programming mode is enabled by applying v pp to the rst pin. the connections required during parallel mode are shown in figure 22-2 . during parallel programming, port 1 is configured as an 8-bit wide bidirectional command bus. data on p1 is strobed by a positive pulse on the xtal1 pin. no other clock is re quired. the interface is enabled by pulling cs (p3.2) low. p3.1 acts as rdy/bsy , and will be pulled low to indicate th at the device is busy regardless of the state of cs . table 22-2. status register ???? load success wrtinh busy bit76543210 symbol function load load flag. cleared low by the load page buffer command and set high by the next memory write. this flag signals that the page buffer was previously loaded with data by the load page buffer command. success success flag. cleared low at the start of a programming cycle and will on ly be set high if th e programming cycle completes without interruption from the brownout detector. wrtinh write inhibit flag. cleared low by the brownout detector (bod) whenever programming is inhibited due to v cc falling below the minimum required programming voltage. if a bod episode occurs during programming, the success flag will remain low after the cycle is complete. wrtinh low also forces busy low. busy busy flag. cleared low whenever the memory is busy programming or if write is currently inhibited.
57 3547f?micro?6/06 at89lp2052/lp4052 figure 22-2. flash parallel programming device connections note: sampling of pin p3.1 (rdy/bsy ) is optional. during parallel programming, p3.1 will be pulled low while the device is busy. note that it does not require an external passive pull-up to v cc . while cs is high, the interface is reset to its default state and p1 is tri-stated. cs should be brought low before the first byte of a command is issued, and should return high only after the last byte of the command has been strobed. figure 22-3 shows a generic parallel write com- mand sequence. command, address, and data bytes are sampled from p1 on the rising edge of the xtal1 pulse. figure 22-4 shows a generic parallel read command sequence. command and address bytes are sampled from p1 on the rising edge of the xtal1 pu lse. at the falling edge of the fourth xtal1 pulse the device enables p1 to output data. the data remains on p1 until cs is brought high. during reads the parallel programmer should tri-state p1 before the negative edge of the fourth xtal1 pulse to avoid bus contention. figure 22-3. parallel write command sequence figure 22-4. parallel read command sequence at89lp2052/lp4052 vcc p1 rst p3.1 x tal 1 p3.2 gnd 2.7 to 5.5v r dy/bsy cs v pp data aah opcode addrh addrl datain cs xtal1 p1 aah opcode addrh addrl dataout cs xtal1 p1
58 3547f?micro?6/06 at89lp2052/lp4052 22.4.1 power-up sequence execute the following sequence to power-up the device before parallel programming. 1. apply power between vcc and gnd pins. 2. after v cc has settled, wait 10 s and bring rst to ?h?. 3. wait 2 ms for the internal power-on reset to time out. 4. bring p3.2 to ?h? and then wait 10 s. 5. raise rst/v pp to 12v to enable the parallel programming modes. 6. after v pp has settled, wait an additional 10 s before programming. figure 22-5. parallel mode power-up operation 22.4.2 power-down sequence execute the following sequence to power-down the device after parallel programming. 1. tri-state p1. 2. bring rst/v pp down from 12v to v cc and wait 10 s. 3. bring xtal and p3.2 to ?l?. 4. bring rst to ?l? and wait 10 s. 5. power off v cc . figure 22-6. parallel mode power-down operation note: the waveforms on this page are not to scale. v cc rst v ih v pp p3.2 xtal1 high z p1 v cc rst v ih v pp p3.2 xtal1 high z p1
59 3547f?micro?6/06 at89lp2052/lp4052 22.4.3 program enable function :  enables the programming interface to receive commands.  program enable must be the first command issued in any programming session. in parallel programming a session is active while rst remains at v pp . in serial programming a session is active while rst remains at v cc . usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to ach and pulse xtal1 high. 4. drive p1 to 53h and pulse xtal1 high. 5. bring cs high. figure 22-7. program enable sequence 22.4.4 chip erase function :  erases (programs ffh to) the entire 2/4-kbyte memory array.  erases user signature row if user row programming fuse bit is enabled.  lockbit1 and lockbit2 are programmed to ?unlock? state. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 8ah and pulse xtal1 high. 4. bring cs high. 5. wait 4 ms, monitor p3.1, or poll data/status. figure 22-8. chip erase sequence note: the waveforms on this page are not to scale. aah ach 53h cs xtal1 p1 aah 8ah cs xtal1 p1 rdy/bsy
60 3547f?micro?6/06 at89lp2052/lp4052 22.4.5 load code page buffer function :  loads 1 page (1 to 32 bytes) of data into the temporary page buffer but does not start programming.  use for interruptible loads or loading non-contiguous bytes to a page.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. one byte of data is loaded from p1 for the current address by the positive edge of a xtal1 pulse. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to the 1st byte of the page when incremented past 31, however previously loaded bytes should not be re-loaded.  the load page buffer command needs to be followed by a write command as the internal buffer is not cleared until either the next write has completed or the programming session ends.  clears bit 3 of the status byte to signal that the buffer contains data. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 51h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 with bits [4:0] of address and pulse xtal1 high. 6. to load data bytes, drive data on p1 and pulse xtal1 high to load one byte and incre- ment to the next address. repeat for additional bytes. only 1-32 bytes may be programmed at one time, including any bytes loaded by a previous load page buffer command. bytes should not be loaded more than once. 7. bring cs high. figure 22-9. load page buffer sequence note: the waveform on this page is not to scale. aah 51h 00h 000 bbbbb din 0 cs xtal1 p1 din 1 din n
61 3547f?micro?6/06 at89lp2052/lp4052 22.4.6 write code page function :  programs 1 page (1 to 32 bytes) of data into the code memory array.  page address determined by bits [11:5] of loaded address.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. one byte of data is loaded from p1 for the current address by the positive edge of a xtal1 pulse. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to the 1st byte of the page when incremented past 31, however previously loaded bytes should not be re-loaded. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 50h and pulse xtal1 high. 4. drive p1 with bits [15:8] of address and pulse xtal1 high. 5. drive p1 with bits [7:0] of address and pulse xtal1 high. 6. to write only previously loaded data, bring cs high before loading additional bytes. to load data bytes, drive data on p1 and pulse xtal1 high to load one byte and increment to the next address. repeat for additional bytes. only 1-32 bytes may be programmed at one time, including any bytes loaded by a previous load page buffer command. bytes should not be loaded more than once. 7. bring cs high. 8. wait 2 ms, monitor p3.1, or poll data/status. note: it is not possible to skip bytes while loading data during write. to load non-contiguous bytes in a page, use the load page buffer command. figure 22-10. write code page sequence note: the waveform on this page is not to scale. aah 50h 0000aaaa aaa bbbbb din 0 cs xtal1 p1 din 1 din n rdy/bsy
62 3547f?micro?6/06 at89lp2052/lp4052 22.4.7 read code page function :  read 1 page (1 to 32 bytes) of data from the code memory array.  page address determined by bits [11:5] of loaded address.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to t he 1st byte of the page w hen incremented past 31.  read data will be output on p1 after the falling edge of f ourth xtal1 pulse (address low byte strobe). the programmer should tri-state p1 prior to this edge to avoid bus contention on p1. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 30h and pulse xtal1 high. 4. drive p1 with bits [15:8] of address and pulse xtal1 high. 5. drive p1 with bits [7:0] of address and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. to read additional data bytes in the page, pulse xtal1 high to increment to the next address. 10. drive cs high. figure 22-11. read code page sequence note: the waveform on this page is not to scale. aah 30h 0000aaaa aaa bbbbb dout 0 cs xtal1 p1 dout 1 doutn
63 3547f?micro?6/06 at89lp2052/lp4052 22.4.8 write user signature page function :  programs 1 to 32 bytes of data into the user signature row.  the user row programming fuse must be enabled before writing to the user signature row.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. one byte of data is loaded from p1 for the current address by the positive edge of a xtal1 pulse. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to the 1st byte of the page when incremented past 31, however previously loaded bytes should not be re-loaded. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 52h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 with bits [4:0] of address and pulse xtal1 high. 6. to write only previously loaded data, bring cs high before loading additional bytes. to load data bytes, drive data on p1 and pulse xtal1 high to load one byte and increment to the next address. repeat for additional bytes. only 1-32 bytes may be programmed at one time, including any bytes loaded by a previous load page buffer command. bytes should not be loaded more than once. 7. bring cs high. 8. wait 2 ms, monitor p3.1, or poll data/status. note: it is not possible to skip bytes while loading data during write. to load non-contiguous bytes in a page, use the load page buffer command. figure 22-12. write user signature page sequence note: the waveform on this page is not to scale. aah 52h 00h 000 bbbbb din 0 cs xtal1 p1 din 1 din n rdy/bsy
64 3547f?micro?6/06 at89lp2052/lp4052 22.4.9 read user signature page function :  read 1 to 32 bytes of data from the user signature row.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to t he 1st byte of the page w hen incremented past 31.  read data will be output on p1 after the falling edge of f ourth xtal1 pulse (address low byte strobe). the programmer should tri-state p1 prior to this edge to avoid bus contention on p1. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 32h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 with bits [4:0] of address and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. to read additional data bytes in the page, pulse xtal1 high to increment to the next address. 10. drive cs high. figure 22-13. read user signature page sequence note: the waveform on this page is not to scale. aah 32h 00h 000 bbbbb dout 0 cs xtal1 p1 dout 1 doutn
65 3547f?micro?6/06 at89lp2052/lp4052 22.4.10 read atmel signature page function :  read 1 to 32 bytes of data from the atmel signature row.  the byte address (offset in page) is initialized to bits [4:0] of the low address byte. the internal address is incremented by one on the negative edge of the xtal1 pulse. the address will wrap around to t he 1st byte of the page w hen incremented past 31.  read data will be output on p1 after the falling edge of f ourth xtal1 pulse (address low byte strobe). the programmer should tri-state p1 prior to this edge to avoid bus contention on p1. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to 38h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 with bits [4:0] of address and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. to read additional data bytes in the page, pulse xtal1 high to increment to the next address. 10. drive cs high. figure 22-14. read atmel signature page sequence note: the waveform on this page is not to scale. aah 38h 00h 000 bbbbb dout 0 cs xtal1 p1 dout 1 doutn
66 3547f?micro?6/06 at89lp2052/lp4052 22.4.11 write lock bits function :  program (lock) lock bits 1 and 2. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to e4h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 to 00h and pulse xtal1 high. 6. drive data on p1 and pulse xtal1 high. 7. drive cs high. 8. wait 4 ms, monitor p3.1, or poll data/status. figure 22-15. write lock bits sequence 22.4.12 read lock bits function :  read status of lock bits 1 and 2. usage : 1. bring cs (p3.2) low. 2. drive p1 to 0xaa and pulse xtal1 high. 3. drive p1 to 0x64 and pulse xtal1 high. 4. drive p1 to 0x00 and pulse xtal1 high. 5. drive p1 to 0x00 and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. drive cs high. figure 22-16. read lock bits sequence note: the waveforms on this page are not to scale. aah e4h 00h 00h 111111ll cs xtal1 p1 rdy/bsy aah 64h 00h 00h 111111ll cs xtal1 p1
67 3547f?micro?6/06 at89lp2052/lp4052 22.4.13 write user fuses function :  program user fuses.  unimplemented bits should always be written with 1s. usage : 1. bring cs (p3.2) low. 2. drive p1 to aah and pulse xtal1 high. 3. drive p1 to e1h and pulse xtal1 high. 4. drive p1 to 00h and pulse xtal1 high. 5. drive p1 to 00h and pulse xtal1 high. 6. drive data on p1 and pulse xtal1 high. 7. drive cs high. 8. wait 4 ms, monitor p3.1, or poll data/status. figure 22-17. write user fuses sequence 22.4.14 read user fuses function :  read status of user fuses usage : 1. bring cs (p3.2) low. 2. drive p1 to 0xaa and pulse xtal1 high. 3. drive p1 to 0x61 and pulse xtal1 high. 4. drive p1 to 0x00 and pulse xtal1 high. 5. drive p1 to 0x00 and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. drive cs high. figure 22-18. read user fuses sequence note: the waveforms on this page are not to scale. aah e1h 00h 00h 1111ffff cs xtal1 p1 rdy/bsy aah 61h 00h 00h 1111ffff cs xtal1 p1
68 3547f?micro?6/06 at89lp2052/lp4052 22.4.15 read status function :  read memory status byte. usage : 1. bring cs (p3.2) low. 2. drive p1 to 0xaa and pulse xtal1 high. 3. drive p1 to 0x60 and pulse xtal1 high. 4. drive p1 to 0x00 and pulse xtal1 high. 5. drive p1 to 0x00 and bring xtal1 high. 6. tri-state p1. 7. bring xtal1 low. 8. read data from p1. 9. drive cs high. figure 22-19. read status sequence note: the waveform on this page is not to scale. aah 60h 00h 00h 1111ssss cs xtal1 p1
69 3547f?micro?6/06 at89lp2052/lp4052 figure 22-20. flash programming and verification waveforms in parallel mode vcc rst p3.2/cs xtal1 port1 (write) p3.1/rdy/bsy port1 (read) t pwrup t por t cstp t hstl t clxh t xth t xtl t dstp t dhld opcode opcode preamble preamble addrh addrh addrl addrl datain t xldo t xldv dataout 0 dataout n t chdz t xlch t chbl t wrc /t ers t bhpg {erase/write} t bhhl t hstl t clrl t pwrdn
70 3547f?micro?6/06 at89lp2052/lp4052 22.5 in-system programming (isp) the at89lp2052/lp4052 offers a serial programming interface which may be used in place of the parallel programming interface or to program the device while in system. in this document serial programming and in-system programming (isp) refer to the same interface. isp supports the same command set as parallel programming. however, during isp command bytes are entered serially over the serial peripheral in terface (spi) pins. the device connections are shown in figure 22-21 . the isp enable user fuse must be enabled through parallel program- ming prior to entering the first isp session. isp itself may disable the isp fuse, however any changes to the isp fuse s will not take affect until the de vice has been powered down and up again. the progra mmer must take care not to accidentally disable the isp fuse as this will make the device unprogrammable through the serial interface. only parallel programming may re- enable the fuse. table 22-3. parallel flash programming and verification parameters symbol parameter min max units v pph programming enable input high voltage 11.5 12.5 v v ppl programming enable input low voltage -0.5 v cc v i pp programming enable current 1.0 ma t pwrup power-on to rst high 10 s t por power-on reset time 2 ms t cstp cs setup to v pp high 10 s t hstl high voltage setting time 10 s t clxh cs low to xtal1 high 100 ns t xth xtal1 high width 125 ns t xtl xtal1 low width 75 ns t dstp data setup to xtal1 high 50 ns t dhld data hold after xtal1 high 50 ns t xldo xtal1 low to data out 20 ns t xldv xtal1 low to data valid 100 ns t xlch xtal1 low to cs high 100 ns t chdz cs high to data tri-state 20 ns t chbl cs high to busy low 3 s t wrc write cycle time 4.5 ms t ers erase cycle time 9 ms t bhpg busy high to next erase/write 3 s t bhhl busy high to v pp off 10 s t clrl cs low to rst low 1 s t pwrdn rst low to power off 1 s
71 3547f?micro?6/06 at89lp2052/lp4052 figure 22-21. isp/serial programming device connections note: sck frequency should be less than 5 mhz. 22.5.1 power-up sequence execute this sequence to power-up the device before serial programming. 1. apply power between vcc and gnd pins. 2. keep sck (p1.7) and ss (p1.4) at ?l?. 3. wait 10 s and bring rst and ss to ?h?. 4. wait at least 2 ms for internal power-on reset to time out. figure 22-22. serial programming power-up sequence at89lp2052/lp4052 vcc rst p1.7/sck p1.5/mosi gnd 2.7 to 5.5v serial clock se rial in v ih p1.4/ss p1.6/miso serial out cs v cc rst ss sck high z miso high z mosi
72 3547f?micro?6/06 at89lp2052/lp4052 22.5.2 power-down sequence execute this sequence to power-down the device after serial programming. 1. tri-state mosi (p1.5). 2. bring sck (p1.7) to ?l?. 3. bring rst to ?l?. 4. bring ss (p1.4) to ?l? 5. power off vcc. figure 22-23. serial programming po wer-down sequence note: the waveforms on this page are not to scale. 22.5.3 isp start sequence execute this sequence to enter isp when the device is already operational. 1. bring ss (p1.4) to ?h?. 2. tri-state miso (p1.6). 3. bring rst to ?h?. 4. bring sck (p1.7) to ?l?. figure 22-24. in-system programming (isp) start sequence v cc rst ss sck high z miso high z mosi v cc rst ss sck high z mosi high z miso xtal1
73 3547f?micro?6/06 at89lp2052/lp4052 22.5.4 isp exit sequence execute this sequence to exit isp and resume execution. 1. bring ss (p1.4) to ?h?. 2. tri-state mosi (p1.5). 3. tri-state sck (p1.7). 4. bring rst to ?l?. 5. tri-state ss . figure 22-25. in-system programming (isp) exit sequence note: the waveforms on this page are not to scale. 22.5.5 isp byte sequence the isp byte sequence is shown in figure 22-26 .  data shifts in/out msb first.  miso changes at falling edge of sck.  mosi is sampled at rising edge of sck. figure 22-26. isp byte sequence v cc rst ss sck high z mosi high z miso xtal1 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0 mosi miso sck data sampled
74 3547f?micro?6/06 at89lp2052/lp4052 22.5.6 isp command sequence the isp multi-byte command sequence is shown in figure 22-27 . ss should be brought low before the first byte in a command is sent and brought back high after the final byte in the command has been sent. the command is not complete until ss returns high.  command bytes are issued serially on mosi (p1.5).  data bytes are output serially on miso (p1.6). figure 22-27. isp command sequence 70 654321 7 0 654321 7 0 654321 7 0 654321 70 654321 ss sck mosi miso preamble opcode address high address low data in data out x x x x table 22-4. serial programming interface parameters symbol parameter min max units t sck serial clock cycle time 200 ns t shsl clock high time 100 ns t slsh clock low time 50 ns t sr rise time 25 ns t sf fall time 25 ns t sis serial input setup time 10 ns t sih serial input hold time 10 ns t soh serial output hold time 10 ns t sov serial output valid time 35 ns t soe output enable time 10 ns t sox output disable time 25 ns t sse ss enable lead time 100 ns t ssd ss disable lag time 100 ns t wrc wire cycle time 4.5 ms t ers erase cycle time 9 ms
75 3547f?micro?6/06 at89lp2052/lp4052 figure 22-28. serial programming interface timing t sr t sse t slsh t sov t sf t sox t ssd t sck t shsl t soe t soh t sih t sis ss sck miso mosi 23. electrical characteristics 23.1 absolute maximum ratings* operating temperature ................................... -40c to +85c note: stresses beyond those listed under ?absolute maxi- mum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or any other condi- tions beyond those indicated in the operational sections of this specificat ion is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature ..................................... -65c to +150c voltage on any pin with respect to ground......-0.7v to +6.2v maximum operating voltage ............................................ 5.5v dc output current...................................................... 15.0 ma
76 3547f?micro?6/06 at89lp2052/lp4052 notes: 1. under steady state (n on-transient) conditions, i ol must be externally limited as follows: maximum i ol per port pin: 10 ma maximum total i ol for all output pins: 15 ma if i ol exceeds the test condition, v ol may exceed the related specification. pins are not guaranteed to sink current greater than the listed test conditions. 2. port in quasi-bidirectional mode 3. port in push-pull output mode 4. minimum v cc for power-down is 2v. 23.2 dc characteristics t a = -40c to 85c, v cc = 2.4v to 5.5v (unless otherwise noted) symbol parameter condition min max units v il input low-voltage (except rst) -0.5 0.25 v cc v v il1 input low-voltage (rst) -0.5 0.3 v cc v v ih input high-voltage (except rst) 0.65 v cc v cc + 0.5 v v ih1 input high-voltage (rst) 0.6 v cc v cc + 0.5 v v ol output low-voltage (ports 1, 3) (1) i ol = 10 ma, v cc = 2.7v, t a = 85c 0.5 v v oh output high-voltage (ports 1, 3) using weak pull-up (2) i oh = -80 a, v cc = 5v 10% 2.4 v i oh = -30 a 0.75 v cc v i oh = -12 a 0.9 v cc v v oh1 output high-voltage (ports 1, 3) using strong pull-up (3) i oh = -10 ma, t a = 85c 0.9 v cc i il logic 0 input current (2) (ports 1, 3) v in = 0.45v -50 a i tl logic 1 to 0 transition current (2) (ports 1, 3) v in = 2v, v cc = 5v 10% -300 a i li input-only leakage current 0 < v in < v cc 10 a v os comparator input offset voltage v cc = 5v 20 mv v cm comparator input common mode voltage 0v cc v rrst reset pull-down resistor 50 150 k ? c io pin capacitance test freq. = 1 mhz, t a = 25c 10 pf i cc power supply current active mode, 12 mhz, v cc = 5.5v/3v 5.5/3.5 ma idle mode, 12 mhz, v cc = 5.5v/3v 3/2 ma power-down mode (4) v cc = 5.5v 5 a v cc = 3v 2 a
77 3547f?micro?6/06 at89lp2052/lp4052 23.3 serial peripheral interface timing table 23-1. spi master characteristics symbol parameter min max units t clcl oscillator period 41.6 ns t sck serial clock cycle time 4t clcl ns t shsl clock high time t sck /2 - 25 ns t slsh clock low time t sck /2 - 25 ns t sr rise time 25 ns t sf fall time 25 ns t sis serial input setup time 10 ns t sih serial input hold time 10 ns t soh serial output hold time 10 ns t sov serial output valid time 35 ns table 23-2. spi slave characteristics symbol parameter min max units t clcl oscillator period 41.6 ns t sck serial clock cycle time 4t clcl ns t shsl clock high time 1.5 t clcl - 25 ns t slsh clock low time 1.5 t clcl - 25 ns t sr rise time 25 ns t sf fall time 25 ns t sis serial input setup time 10 ns t sih serial input hold time 10 ns t soh serial output hold time 10 ns t sov serial output valid time 35 ns t soe output enable time 10 ns t sox output disable time 25 ns t sse slave enable lead time 10 ns t ssd slave disable lag time 0 ns
78 3547f?micro?6/06 at89lp2052/lp4052 figure 23-1. spi master timing (cpha = 0) figure 23-2. spi slave timing (cpha = 0) figure 23-3. spi master timing (cpha = 1) ss sck (cpol = 0) sck (cpol = 1) miso mosi t sr t sck t slsh t slsh t shsl t shsl t soh t sf t sis t sih t sov t sr t sse t slsh t shsl t sov t sf t sox t ssd t sck t slsh t shsl t soe t soh t sih t sis ss sck (cpol = 0) sck (cpol= 1) miso mosi t shsl t slsh t shsl t slsh t sck t soh t sf t sr t sis t sov t sih ss sck (cpol = 0) sck (cpol = 1) miso mosi
79 3547f?micro?6/06 at89lp2052/lp4052 figure 23-4. spi slave timing (cpha = 1) 23.4 external clock drive figure 23-5. external clock drive waveform ss sck (cpol = 0) sck (cpol = 1) miso mosi t sck t sse t shsl t shsl t slsh t slsh t ssd t sih t sis t soe t sov t soh t sox t sf t sr table 23-3. external clock drive parameters symbol parameter v cc = 2.4v to 5.5v units min max 1/t clcl oscillator frequency 0 20 mhz t clcl clock period 50 ns t chcx high time 12 ns t clcx low time 12 ns t clch rise time 5 ns t chcl fall time 5ns
80 3547f?micro?6/06 at89lp2052/lp4052 note: 1. the values in this table are valid for v cc = 2.4v to 5.5v and load capacitance = 80 pf. figure 23-6. shift register mode timing waveforms 23.6 test conditions 23.6.1 ac testing input/output waveforms (1) note: 1. ac inputs during testing are driven at v cc - 0.5v for a logic ?1? and 0.45v for a logic ?0?. timing measurements are made at v ih min. for a logic ?1? and v il max. for a logic ?0?. 23.6.2 float waveforms (1) note: 1. for timing purposes, a port pin is no longer floating when a 100 mv change from load voltage occurs. a port pin begins t o float when 100 mv change from the loaded v oh /v ol level occurs. 23.5 serial port timing : shift register mode table 23-4. serial port shift regist er timing parameters (1) symbol parameter variable oscillator units min max t xlxl serial port clock cycle time 2t clcl -15 s t qvxh output data setup to clock rising edge t clcl -15 ns t xhqx output data hold after clock rising edge t clcl -15 ns t xhdx input data hold after clock rising edge 0 ns t xhdv input data valid to clock rising edge 15 ns 01234567 valid valid valid valid valid valid valid valid clock write to sbuf output data clear ri input data
81 3547f?micro?6/06 at89lp2052/lp4052 23.6.3 i cc test condition, active mode , all other pins are disconnected 23.6.4 i cc test condition, idle mode, all other pins are disconnected 23.6.5 clock signal waveform for i cc tests in active and idle modes, t clch = t chcl = 5 ns 23.6.6 i cc test condition, power-down mode, all other pins are disconnected, v cc = 2v to 5.5v xtal2 rst v cc v cc v cc i cc xtal1 p1, p3 gnd (nc) clock signal xtal2 rst v cc v cc v cc i cc xtal1 p1, p3 gnd (nc) clock signal v cc - 0.5v 0.45v 0.2 v cc - 0.1v 0.7 v cc t chcx t chcx t clch t chcl t clcl xtal2 rst v cc v cc v cc i cc xtal1 p1, p3 gnd (nc)
82 3547f?micro?6/06 at89lp2052/lp4052 24. ordering information 24.1 standard package speed (mhz) power supply ordering code package operation range 20 2.4v to 5.5v at89lp2052-20pi at89lp2052-20si at89lp2052-20xi 20p3 20s2 20x industrial (-40 c to 85 c) at89LP4052-20pi at89LP4052-20si at89LP4052-20xi 20p3 20s2 20x 24.2 green package op tion (pb/halide-free) speed (mhz) power supply ordering code package operation range 20 2.4v to 5.5v at89lp2052-20pu at89lp2052-20su at89lp2052-20xu 20p3 20s2 20x industrial (-40 c to 85 c) at89LP4052-20pu at89LP4052-20su at89LP4052-20xu 20p3 20s2 20x package type 20p3 20-lead, 0.300? wide, plastic dual in-line package (pdip) 20s2 20-lead, 0.300? wide, plastic gull wing small outline (soic) 20x 20-lead, 4.4 mm body width, plastic th in shrink small outline package (tssop)
83 3547f?micro?6/06 at89lp2052/lp4052 25. packaging information 25.1 20p3 ? pdip 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 20p3 , 20-lead (0.300"/7.62 mm wide) plastic dual inline package (pdip) d 20p3 1/23/04 pin 1 e1 a1 b e b1 c l seating plane a d e eb ec common dimensions (unit of measure = mm) symbol min nom max note a ? ? 5.334 a1 0.381 ? ? d 24.892 ? 26.924 note 2 e 7.620 ? 8.255 e1 6.096 ? 7.112 note 2 b 0.356 ? 0.559 b1 1.270 ? 1.551 l 2.921 ? 3.810 c 0.203 ? 0.356 eb ? ? 10.922 ec 0.000 ? 1.524 e 2.540 typ notes: 1. this package conforms to jedec reference ms-001, variation ad. 2. dimensions d and e1 do not include mold flash or protrusion. mold flash or protrusion shall not exceed 0.25 mm (0.010").
84 3547f?micro?6/06 at89lp2052/lp4052 25.2 20s2 ? soic 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 20s2 , 20-lead, 0.300" wide body, plastic gull wing small outline package (soic) 1/9/02 20s2 a l a1 end view side view top view h e b n 1 e a d c common dimensions (unit of measure = inches) symbol min nom max note notes: 1. this drawing is for general information only; refer to jedec drawing ms-013, variation ac for additional information. 2. dimension "d" does not include mold flash, protrusions or gate burrs. mold flash, protrusions and gate burrs shall not exc eed 0.15 mm (0.006") per side. 3. dimension "e" does not include inter-lead flash or protrusion. inter-lead flash and protrusions shall not exceed 0.25 mm (0.010") per side. 4. "l" is the length of the terminal for soldering to a substrate. 5. the lead width "b", as measured 0.36 mm (0.014") or greater above the seating plane, shall not exceed a maximum value of 0.61 mm (0.024") per side. a 0.0926 0.1043 a1 0.0040 0.0118 b 0.0130 0.0200 4 c 0.0091 0.0125 d 0.4961 0.5118 1 e 0.2914 0.2992 2 h 0.3940 0.4190 l 0.0160 0.050 3 e 0.050 bsc
85 3547f?micro?6/06 at89lp2052/lp4052 25.3 20x ? tssop 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 20x , (formerly 20t), 20-lead, 4.4 mm body width, plastic thin shrink small outline package (tssop) c 20x 10/23/03 6.60 (.260) 6.40 (.252) 1.20 (0.047) max 0.65 (.0256) bsc 0.20 (0.008) 0.09 (0.004) 0.15 (0.006) 0.05 (0.002) index mark 6.50 (0.256) 6.25 (0.246) seating plane 4.50 (0.177) 4.30 (0.169) pin 1 0.75 (0.030) 0.45 (0.018) 0o ~ 8o 0.30 (0.012) 0.19 (0.007) dimensions in millimeters and (inches). controlling dimension: millimeters. jedec standard mo-153 ac
86 3547f?micro?6/06 at89lp2052/lp4052 26. revision history revision a ? march 2005 ? initial release revision b ? june 2005 ? last paragraph in section 12.2 on page 12 was inserted. revision c ? august 2005 ? in table 15-3 on page 23 , changed the sfr address for tconb from 88h to 91h. ? changed the maximum bit frequency from f/2 to f/4 in the ?serial peripheral interface? on page 39 . ? in the ?spi block diagram? on page 40 , the 16-bit reference was deleted from shift register box. ? in the ?spsr ? spi status register? on page 43 , the divider ratios were changed to the following: 483264 ? replaced cm3 with cm2 in bit 2 of register acsr ( page 47 ) ? in the ?programming command summary? on page 55 , several changes were made in specific bit positions within the addr high , addr low and data 0 columns. revision d ? april 2006 ? added rohs compliant device offerings. revision e ? june 2006 ? in pages 1 , 79 and 80 , the reference to v cc = 2.7v were changed to 2.4v. on page 76 the maximum rating for the operating temperature was changed from +125 c to +85 c. revision f ? june 2006 ? in table 6-1 on page 6 , changed the sfr address of spdr from 85h to 86h.
1 3547f?micro?6/06 at89lp2052/lp4052 table of contents 1 description ............ .............. .............. ............... .............. .............. ............ 1 2 pin configuration ..... ................ ................ ................. ................ ............... 2 2.120-lead pdip/soic/tssop ......................................................................................2 3 pin description ......... ................ ................ ................. ................ ............... 3 4 block diagram ............ ................ ................. ................ ................. ............ 4 5 memory organization ......... .............. ............... .............. .............. ............ 4 5.1program memory .......................................................................................................4 5.2data memory .............................................................................................................5 6 special function registers ..... ................ ................. ................ ............... 6 7 comparison to standard 8051 .. ................. ................ ................. ............ 7 7.1system clock ............................................................................................................7 7.2instruction execution with single-cycle fetch ...........................................................7 7.3interrupt handling ......................................................................................................7 7.4timer/counters ..........................................................................................................7 7.5serial port ................................................................................................................ ..7 7.6watchdog timer ........................................................................................................7 7.7i/o ports .................................................................................................................. ..8 7.8reset ...................................................................................................................... ...8 8 enhanced cpu ............. ................. ................ ................. .............. ............ 8 9 restrictions on certain instr uctions .............. .............. .............. .......... 10 9.1branching instructions .............................................................................................10 9.2movx-related instructions, data memory ...............................................................10 10 system clock ........... ................ ................ ................. ................ ............. 10 10.1crystal oscillator ...................................................................................................10 10.2external clock source ...........................................................................................10 10.3system clock out ..................................................................................................10 11 reset ............. ................ ................. ................ ................. .............. .......... 11 11.1power-on reset .....................................................................................................11 11.2brown-out reset ....................................................................................................11 11.3external reset .......................................................................................................11 11.4watchdog reset ....................................................................................................11
2 3547f?micro?6/06 at89lp2052/lp4052 [preliminary] table of contents (continued) 12 power saving modes .......... .............. ............... .............. .............. .......... 11 12.1idle mode ...............................................................................................................12 12.2power-down mode ................................................................................................12 13 interrupts ............... .............. .............. ............... .............. .............. .......... 13 13.1interrupt response time .......................................................................................14 14 i/o ports ............... ................ .............. ............... .............. .............. .......... 17 14.1quasi-bidirectional output .....................................................................................17 14.2input-only mode .....................................................................................................18 14.3open-drain output .................................................................................................19 14.4push-pull output ....................................................................................................19 14.5port 1 analog functions ........................................................................................19 14.6port read-modify-write .........................................................................................20 14.7port alternate functions ........................................................................................20 15 enhanced timer/counters ...... ................ ................. ................ ............. 21 15.1mode 0 ..................................................................................................................21 15.2mode 1 ..................................................................................................................22 15.3mode 2 ..................................................................................................................23 15.4mode 3 ..................................................................................................................23 15.5pulse width modulation .........................................................................................26 15.6timer/counter pin configuration ...........................................................................27 16 external interrupts .......... ................ ................. .............. .............. .......... 27 17 serial interface ................ ................ ................. .............. .............. .......... 28 17.1multiprocessor communications ...........................................................................28 17.2baud rates ............................................................................................................30 17.3more about mode 0 ...............................................................................................31 17.4more about mode 1 ...............................................................................................33 17.5more about modes 2 and 3 ...................................................................................35 17.6framing error detection ........................................................................................38 17.7automatic address recognition ............................................................................38
3 3547f?micro?6/06 at89lp2052/lp4052 table of contents (continued) 18 serial peripheral interface .. .............. ............... .............. .............. .......... 39 18.1normal mode .........................................................................................................41 18.2enhanced mode ....................................................................................................41 18.3serial clock generator ..........................................................................................44 18.4spi pin configuration ............................................................................................45 19 analog comparator ............ .............. ............... .............. .............. .......... 46 19.1comparator interrupt with debouncing .................................................................46 20 programmable watchdog timer .. ................ ................. .............. .......... 48 21 instruction set summary ... .............. ............... .............. .............. .......... 49 22 programming the flash memory .................... .............. .............. .......... 54 22.1programming command summary .......................................................................55 22.2status register ......................................................................................................56 22.3data polling .........................................................................................................56 22.4parallel programming ............................................................................................56 22.5in-system programming (isp) ...............................................................................70 23 electrical characteristics ... .............. ............... .............. .............. .......... 75 23.1absolute maximum ratings* .................................................................................75 23.2dc characteristics ................................................................................................76 23.3serial peripheral interface timing .........................................................................77 23.4external clock drive ..............................................................................................79 23.5serial port timing: shift register mode ................................................................80 23.6test conditions .....................................................................................................80 24 ordering information .......... .............. ............... .............. .............. .......... 82 24.1standard package .................................................................................................82 25 packaging information .......... .............. .............. .............. .............. ........ 83 25.120p3 ? pdip ..........................................................................................................83 25.220s2 ? soic .........................................................................................................84 25.320x ? tssop ........................................................................................................85 26 revision history........ ................ ................ ................. ................ ............. 86
printed on recycled paper. 3547f?micro?6/06 xm disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in atmel?s terms and condi- tions of sale located on atmel? s web site, atmel assumes no liability whatsoever and disclaims any express, implied or statutor y warranty relating to its products including, but not limited to , the implied warranty of merchantability, fitness for a particu lar purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, conseque ntial, punitive, special or i nciden- tal damages (including, without limitation, damages for loss of profits, business interruption, or loss of information) arising out of the use or inability to use this document, even if at mel has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or co mpleteness of the contents of this document and reserves the rig ht to make changes to specifications and product descriptions at any time without notice. atmel does not make any commitment to update the information contained her ein. unless specifically provided otherwise, atmel products are not suitable for, and shall not be used in, automotive applications. atmel?s products are not int ended, authorized, or warranted for use as components in applications in tended to support or sustain life. atmel corporation atmel operations 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 487-2600 regional headquarters europe atmel sarl route des arsenaux 41 case postale 80 ch-1705 fribourg switzerland tel: (41) 26-426-5555 fax: (41) 26-426-5500 asia room 1219 chinachem golden plaza 77 mody road tsimshatsui east kowloon hong kong tel: (852) 2721-9778 fax: (852) 2722-1369 japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (81) 3-3523-3551 fax: (81) 3-3523-7581 memory 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 436-4314 microcontrollers 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 436-4314 la chantrerie bp 70602 44306 nantes cedex 3, france tel: (33) 2-40-18-18-18 fax: (33) 2-40-18-19-60 asic/assp/smart cards zone industrielle 13106 rousset cedex, france tel: (33) 4-42-53-60-00 fax: (33) 4-42-53-60-01 1150 east cheyenne mtn. blvd. colorado springs, co 80906, usa tel: 1(719) 576-3300 fax: 1(719) 540-1759 scottish enterprise technology park maxwell building east kilbride g75 0qr, scotland tel: (44) 1355-803-000 fax: (44) 1355-242-743 rf/automotive theresienstrasse 2 postfach 3535 74025 heilbronn, germany tel: (49) 71-31-67-0 fax: (49) 71-31-67-2340 1150 east cheyenne mtn. blvd. colorado springs, co 80906, usa tel: 1(719) 576-3300 fax: 1(719) 540-1759 biometrics/imagin g/hi-rel mpu/ high speed converters/rf datacom avenue de rochepleine bp 123 38521 saint-egreve cedex, france tel: (33) 4-76-58-30-00 fax: (33) 4-76-58-34-80 literature requests www.atmel.com/literature ? 2006 atmel corporation. all rights reserved. atmel ? , logo and combinations thereof, everywhere you are ? and others, are registered trademarks or trademarks of atmel corporation or its subsidiaries. other terms and product names may be trademarks of others.


▲Up To Search▲   

 
Price & Availability of 89LP4052

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X